diff --git a/libcxx/include/__config b/libcxx/include/__config --- a/libcxx/include/__config +++ b/libcxx/include/__config @@ -1440,7 +1440,13 @@ #endif #if __has_attribute(init_priority) -# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(101))) + // TODO: Remove this once we drop support for building libc++ with old Clangs +# if (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER < 1200) || \ + (defined(__apple_build_version__) && __apple_build_version__ < 13000000) +# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(101))) +# else +# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(100))) +# endif #else # define _LIBCPP_INIT_PRIORITY_MAX #endif diff --git a/libcxx/src/experimental/memory_resource.cpp b/libcxx/src/experimental/memory_resource.cpp --- a/libcxx/src/experimental/memory_resource.cpp +++ b/libcxx/src/experimental/memory_resource.cpp @@ -76,12 +76,7 @@ ~ResourceInitHelper() {} }; -// When compiled in C++14 this initialization should be a constant expression. -// Only in C++11 is "init_priority" needed to ensure initialization order. -#if _LIBCPP_STD_VER > 11 -_LIBCPP_SAFE_STATIC -#endif -ResourceInitHelper res_init _LIBCPP_INIT_PRIORITY_MAX; +_LIBCPP_SAFE_STATIC ResourceInitHelper res_init; } // end namespace diff --git a/libcxx/src/iostream.cpp b/libcxx/src/iostream.cpp --- a/libcxx/src/iostream.cpp +++ b/libcxx/src/iostream.cpp @@ -77,7 +77,12 @@ #endif ; +// Hacky way to make the compiler believe that we're inside a system header so +// it doesn't flag the use of the init_priority attribute with a value that's +// reserved for the implementation (we're the implementation). +# 80 "iostream.cpp" 1 3 _LIBCPP_HIDDEN ios_base::Init __start_std_streams _LIBCPP_INIT_PRIORITY_MAX; +# 82 "iostream.cpp" 2 // On Windows the TLS storage for locales needs to be initialized before we create // the standard streams, otherwise it may not be alive during program termination