From 5891e7302f897771c9686a80a4afbf6a36d9b2ac Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Wed, 4 Mar 2020 13:54:04 -0500 Subject: [PATCH] [libc++] Move std::string extern template declarations to end of class. They need to appear before any member functions are ODR used, because they change the visibility of many of these functions and otherwise they could end up with hidden visibility in the DSO. --- libcxx/include/string | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/libcxx/include/string b/libcxx/include/string index ffa8c66..e8245bf 100644 --- a/libcxx/include/string +++ b/libcxx/include/string @@ -1672,6 +1672,17 @@ private: friend basic_string operator+<>(const basic_string&, value_type); }; +// These declarations must appear before any functions are implicitly used +// so that they have the correct visibility specifier. +#ifdef _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION +_LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, char) +_LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, wchar_t) +#else +_LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, char) +_LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, wchar_t) +#endif + + #ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES template::value_type, @@ -4413,14 +4424,6 @@ basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* #endif // _LIBCPP_DEBUG_LEVEL >= 2 -#ifdef _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION -_LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, char) -_LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, wchar_t) -#else -_LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, char) -_LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, wchar_t) -#endif - #if _LIBCPP_STD_VER > 11 // Literal suffixes for basic_string [basic.string.literals] inline namespace literals -- 2.7.4