diff --git a/libcxx/include/__availability b/libcxx/include/__availability --- a/libcxx/include/__availability +++ b/libcxx/include/__availability @@ -179,6 +179,11 @@ // # define _LIBCPP_AVAILABILITY_HAS_NO_TZDB # define _LIBCPP_AVAILABILITY_TZDB +// Enable additional explicit instantiations of iostreams components. This +// reduces the number of weak definitions generated in programs that use +// iostreams by providing a single strong definition in the shared library. +// # define _LIBCPP_AVAILABILITY_HAS_NO_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1 + #elif defined(__APPLE__) // shared_mutex and shared_timed_mutex @@ -356,6 +361,12 @@ # define _LIBCPP_AVAILABILITY_HAS_NO_TZDB # define _LIBCPP_AVAILABILITY_TZDB __attribute__((unavailable)) +# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 120000) || \ + (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 150000) || \ + (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 150000) || \ + (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 80000) +# define _LIBCPP_AVAILABILITY_HAS_NO_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1 +# endif #else // ...New vendors can add availability markup here... diff --git a/libcxx/include/__config b/libcxx/include/__config --- a/libcxx/include/__config +++ b/libcxx/include/__config @@ -176,11 +176,6 @@ # endif # if defined(_LIBCPP_BUILDING_LIBRARY) || _LIBCPP_ABI_VERSION >= 2 -// Enable additional explicit instantiations of iostreams components. This -// reduces the number of weak definitions generated in programs that use -// iostreams by providing a single strong definition in the shared library. -# define _LIBCPP_ABI_ENABLE_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1 - // Define a key function for `bad_function_call` in the library, to centralize // its vtable and typeinfo to libc++ rather than having all other libraries // using that class define their own copies. diff --git a/libcxx/include/fstream b/libcxx/include/fstream --- a/libcxx/include/fstream +++ b/libcxx/include/fstream @@ -1734,7 +1734,7 @@ this->setstate(ios_base::failbit); } -#if defined(_LIBCPP_ABI_ENABLE_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1) +#ifndef _LIBCPP_AVAILABILITY_HAS_NO_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ifstream; extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ofstream; extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_filebuf; diff --git a/libcxx/include/sstream b/libcxx/include/sstream --- a/libcxx/include/sstream +++ b/libcxx/include/sstream @@ -1192,8 +1192,16 @@ __x.swap(__y); } -#if defined(_LIBCPP_ABI_ENABLE_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1) +#ifndef _LIBCPP_AVAILABILITY_HAS_NO_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1 +// TODO: Remove this condition once GCC supports exclude_from_explicit_instantiation +#if !defined(_LIBCPP_COMPILER_GCC) || defined(_LIBCPP_BUILDING_LIBRARY) + +// This is a work-around for https://llvm.org/PR41018 +// TODO(LLVM-20): Remove this condition +#if !defined(_WIN32) || _LIBCPP_CLANG_VER >= 1800 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_stringbuf; +#endif +#endif extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_stringstream; extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostringstream; extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istringstream; diff --git a/libcxx/src/ios.instantiations.cpp b/libcxx/src/ios.instantiations.cpp --- a/libcxx/src/ios.instantiations.cpp +++ b/libcxx/src/ios.instantiations.cpp @@ -31,7 +31,7 @@ #endif // Additional instantiations added later. Whether programs rely on these being -// available is protected by _LIBCPP_ABI_ENABLE_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1. +// available is protected by _LIBCPP_AVAILABILITY_HAS_NO_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1. template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_stringbuf; template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_stringstream; template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ostringstream;