@@ -577,15 +577,27 @@ typedef __char32_t char32_t;
577577# define _LIBCPP_POP_EXTENSION_DIAGNOSTICS
578578# endif
579579
580- // Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect.
581580// clang-format off
582- # define _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS \
583- namespace _LIBCPP_TYPE_VISIBILITY_DEFAULT std { \
584- inline namespace _LIBCPP_ABI_NAMESPACE {
585- # define _LIBCPP_END_NAMESPACE_STD }} _LIBCPP_POP_EXTENSION_DIAGNOSTICS
586581
587- #define _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL namespace std { namespace experimental {
588- #define _LIBCPP_END_NAMESPACE_EXPERIMENTAL }}
582+ // The unversioned namespace is used when we want to be ABI compatible with other standard libraries in some way. There
583+ // are two main categories where that's the case:
584+ // - Historically, we have made exception types ABI compatible with libstdc++ to allow throwing them between libstdc++
585+ // and libc++. This is not used anymore for new exception types, since there is no use-case for it anymore.
586+ // - Types and functions which are used by the compiler are in the unversioned namespace, since the compiler has to know
587+ // their mangling without the appropriate declaration in some cases.
588+ // If it's not clear whether using the unversioned namespace is the correct thing to do, it's not. The versioned
589+ // namespace (_LIBCPP_BEGIN_NAMESPACE_STD) should almost always be used.
590+ # define _LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD \
591+ _LIBCPP_PUSH_EXTENSION_DIAGNOSTICS namespace _LIBCPP_TYPE_VISIBILITY_DEFAULT std {
592+
593+ # define _LIBCPP_END_UNVERSIONED_NAMESPACE_STD } _LIBCPP_POP_EXTENSION_DIAGNOSTICS
594+
595+ # define _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD inline namespace _LIBCPP_ABI_NAMESPACE {
596+ # define _LIBCPP_END_NAMESPACE_STD } _LIBCPP_END_UNVERSIONED_NAMESPACE_STD
597+
598+ // TODO: This should really be in the versioned namespace
599+ #define _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL _LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD namespace experimental {
600+ #define _LIBCPP_END_NAMESPACE_EXPERIMENTAL } _LIBCPP_END_UNVERSIONED_NAMESPACE_STD
589601
590602#define _LIBCPP_BEGIN_NAMESPACE_LFTS _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace fundamentals_v1 {
591603#define _LIBCPP_END_NAMESPACE_LFTS } _LIBCPP_END_NAMESPACE_EXPERIMENTAL
0 commit comments