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,17 @@ #endif ; -_LIBCPP_HIDDEN ios_base::Init __start_std_streams; +// Detect if the init_priority attribute is supported. +#if (defined(_LIBCPP_COMPILER_GCC) && defined(__APPLE__)) \ + || defined(_LIBCPP_COMPILER_MSVC) +// GCC on Apple doesn't support the init priority attribute, +// and MSVC doesn't support any GCC attributes. +# define _LIBCPP_INIT_PRIORITY_MAX +#else +# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((init_priority(101))) +#endif + +_LIBCPP_HIDDEN ios_base::Init __start_std_streams _LIBCPP_INIT_PRIORITY_MAX; // 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