From b3a133e196f4abc6c371ec13d69c9340da8041c2 Mon Sep 17 00:00:00 2001 From: Flamefire Date: Sat, 4 Jan 2025 12:48:27 +0100 Subject: [PATCH 1/2] Add reproducer for Clang < 15 bug with string_view & C++11 char types --- test/sv_conversion_test.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/sv_conversion_test.cpp b/test/sv_conversion_test.cpp index f9cec64e..50ea714a 100644 --- a/test/sv_conversion_test.cpp +++ b/test/sv_conversion_test.cpp @@ -29,6 +29,29 @@ boost::core::string_view f( boost::core::string_view const& str ) return str; } +template +boost::core::basic_string_view f( boost::core::basic_string_view const& str ) +{ + return str; +} + +template +void subtest() +{ + std::basic_string s1( 3, Char('1') ); + s1[1] = Char('2'); + s1[2] = Char('3'); + + std::basic_string s2 = f( s1 ); + BOOST_TEST( s1 == s2 ); + +#if ! (defined(BOOST_CLANG) && BOOST_CLANG_VERSION < 150000) + // leads to undefined symbols in Clang < 15: https://github.com/llvm/llvm-project/issues/55560 + std::basic_string s3( (f( s1 )) ); + BOOST_TEST( s1 == s3 ); +#endif +} + int main() { { @@ -62,5 +85,15 @@ int main() #endif +#if !defined(BOOST_NO_CXX11_CHAR16_T) + subtest(); +#endif +#if !defined(BOOST_NO_CXX11_CHAR32_T) + subtest(); +#endif +#if defined(__cpp_char8_t) && __cpp_char8_t >= 201811L + subtest(); +#endif + return boost::report_errors(); } From e5e0c5028d792fd9e472e25b5426d686720e0c9d Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Sat, 4 Jan 2025 11:58:34 +0100 Subject: [PATCH 2/2] Workaround clang bug Clang < 15 has a bug in c++-20 mode where using the `std::basic_string` constructor taking a pointer and size leads to an undefined symbol `M_construct` when used with Unicode char types Avoid this by using the range constructor. --- include/boost/core/detail/string_view.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/core/detail/string_view.hpp b/include/boost/core/detail/string_view.hpp index 8f9ab355..85fd3538 100644 --- a/include/boost/core/detail/string_view.hpp +++ b/include/boost/core/detail/string_view.hpp @@ -422,7 +422,7 @@ template class basic_string_view template operator std::basic_string, A>() const { - return std::basic_string, A>( data(), size() ); + return std::basic_string, A>( begin(), end() ); } #if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)