From: Jonathan Wakely Date: Thu, 1 Feb 2024 21:40:33 +0000 (+0000) Subject: libstdc++: Allow explicit conversion of string views with different traits X-Git-Tag: releases/gcc-12.4.0~420 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6e7b1527902e1e54c1a24af5bec0cc11a9af3ea4;p=thirdparty%2Fgcc.git libstdc++: Allow explicit conversion of string views with different traits This was changed by LWG 3857. libstdc++-v3/ChangeLog: * include/std/string_view (basic_string_view(R&&)): Remove constraint that traits_type must be the same, as per LWG 3857. * testsuite/21_strings/basic_string_view/cons/char/range_c++20.cc: Explicit conversion between different specializations should be allowed. * testsuite/21_strings/basic_string_view/cons/wchar_t/range_c++20.cc: Likewise. (cherry picked from commit f60d7e1c64518936797ec1009cb49f72f8fe45b9) --- diff --git a/libstdc++-v3/include/std/string_view b/libstdc++-v3/include/std/string_view index e8c8bf7e4cd2..9ee888363813 100644 --- a/libstdc++-v3/include/std/string_view +++ b/libstdc++-v3/include/std/string_view @@ -160,8 +160,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION && (!requires (_DRange& __d) { __d.operator ::std::basic_string_view<_CharT, _Traits>(); }) - && (!requires { typename _DRange::traits_type; } - || is_same_v) constexpr explicit basic_string_view(_Range&& __r) noexcept(noexcept(ranges::size(__r)) && noexcept(ranges::data(__r))) diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/cons/char/range_c++20.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/cons/char/range_c++20.cc index a5745fcb6033..1ba72a03f274 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string_view/cons/char/range_c++20.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/cons/char/range_c++20.cc @@ -116,23 +116,10 @@ test02() static_assert( ! std::is_constructible_v ); using V2 = std::basic_string_view>; - // V2::traits_type is not the right type - static_assert( ! std::is_constructible_v ); - - struct V3 : V2 - { - private: - using V2::traits_type; - }; - // V3::traits_type is not a valid (accessible) type - static_assert( std::is_constructible_v ); - - struct V4 : V2 - { - using traits_type = std::string_view::traits_type; - }; - // V4::traits_type is the right type - static_assert( std::is_constructible_v ); + // LWG 3857 + // basic_string_view should allow explicit conversion when only traits vary + static_assert( std::is_constructible_v ); + static_assert( ! std::is_convertible_v ); } void diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/cons/wchar_t/range_c++20.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/cons/wchar_t/range_c++20.cc index af3c986e56f5..85e0531d2d7d 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string_view/cons/wchar_t/range_c++20.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/cons/wchar_t/range_c++20.cc @@ -116,23 +116,10 @@ test02() static_assert( ! std::is_constructible_v ); using V2 = std::basic_string_view>; - // V2::traits_type is not the right type - static_assert( ! std::is_constructible_v ); - - struct V3 : V2 - { - private: - using V2::traits_type; - }; - // V3::traits_type is not a valid (accessible) type - static_assert( std::is_constructible_v ); - - struct V4 : V2 - { - using traits_type = std::wstring_view::traits_type; - }; - // V4::traits_type is the right type - static_assert( std::is_constructible_v ); + // LWG 3857 + // basic_string_view should allow explicit conversion when only traits vary + static_assert( std::is_constructible_v ); + static_assert( ! std::is_convertible_v ); } void