These derived classes (std::__1::bad_weak_ptr, std::bad_variant_access, std::bad_any_cast, std::bad_optional_access) of std::exception should not be built twice when we build the library in ASCII & EBCDIC modes for z/OS (https://reviews.llvm.org/D118503). Therefore for z/OS we move the definitions into new files and build them as a separate library in addition to the ASCII/EBCDIC versions of the library. This does not affect other platforms as we would add these files to LIBCXX_SOURCES in CMakeLists.txt and build them normally.
To remove the ABI namespace in std::__1::bad_weak_ptr for z/OS but not affecting other platforms, we define two new namespace macros _LIBCPP_BEGIN_NAMESPACE_EXCEPTION and _LIBCPP_END_NAMESPACE_EXCEPTION and use these as its namespace. This namespace would be defined to std:: for z/OS and _LIBCPP_BEGIN_NAMESPACE_STD/_LIBCPP_END_NAMESPACE_STD for other platforms.