]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Allow explicit conversion of string views with different traits
authorJonathan Wakely <jwakely@redhat.com>
Thu, 1 Feb 2024 21:40:33 +0000 (21:40 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 8 Feb 2024 12:17:43 +0000 (12:17 +0000)
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)

libstdc++-v3/include/std/string_view
libstdc++-v3/testsuite/21_strings/basic_string_view/cons/char/range_c++20.cc
libstdc++-v3/testsuite/21_strings/basic_string_view/cons/wchar_t/range_c++20.cc

index 4cf5bc30fec5dbdef900a15883e06e298a6e69fc..0f4b224353353f0f139d05991d861f3a9f1c8643 100644 (file)
@@ -167,8 +167,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
          && (!requires (_DRange& __d) {
                __d.operator ::std::basic_string_view<_CharT, _Traits>();
              })
-         && (!requires { typename _DRange::traits_type; }
-             || is_same_v<typename _DRange::traits_type, _Traits>)
        constexpr explicit
        basic_string_view(_Range&& __r)
        noexcept(noexcept(ranges::size(__r)) && noexcept(ranges::data(__r)))
index 0d0fd0f3775a760b8f106ccf37a904d45f423e9e..6d253c835311551a6150be2091dd5ea4c60c14f3 100644 (file)
@@ -116,23 +116,10 @@ test02()
   static_assert( ! std::is_constructible_v<std::string_view, V1> );
 
   using V2 = std::basic_string_view<char, __gnu_cxx::char_traits<char>>;
-  // V2::traits_type is not the right type
-  static_assert( ! std::is_constructible_v<std::string_view, V2> );
-
-  struct V3 : V2
-  {
-  private:
-    using V2::traits_type;
-  };
-  // V3::traits_type is not a valid (accessible) type
-  static_assert( std::is_constructible_v<std::string_view, V3> );
-
-  struct V4 : V2
-  {
-    using traits_type = std::string_view::traits_type;
-  };
-  // V4::traits_type is the right type
-  static_assert( std::is_constructible_v<std::string_view, V4> );
+  // LWG 3857
+  // basic_string_view should allow explicit conversion when only traits vary
+  static_assert( std::is_constructible_v<std::string_view, V2> );
+  static_assert( ! std::is_convertible_v<V2, std::string_view> );
 }
 
 void
index de2244467242aec4b82d89908bd6a5572a92a7a2..2096de76badd2703898d2ddc290b2c9081d784b0 100644 (file)
@@ -116,23 +116,10 @@ test02()
   static_assert( ! std::is_constructible_v<std::wstring_view, V1> );
 
   using V2 = std::basic_string_view<wchar_t, __gnu_cxx::char_traits<wchar_t>>;
-  // V2::traits_type is not the right type
-  static_assert( ! std::is_constructible_v<std::wstring_view, V2> );
-
-  struct V3 : V2
-  {
-  private:
-    using V2::traits_type;
-  };
-  // V3::traits_type is not a valid (accessible) type
-  static_assert( std::is_constructible_v<std::wstring_view, V3> );
-
-  struct V4 : V2
-  {
-    using traits_type = std::wstring_view::traits_type;
-  };
-  // V4::traits_type is the right type
-  static_assert( std::is_constructible_v<std::wstring_view, V4> );
+  // LWG 3857
+  // basic_string_view should allow explicit conversion when only traits vary
+  static_assert( std::is_constructible_v<std::wstring_view, V2> );
+  static_assert( ! std::is_convertible_v<V2, std::wstring_view> );
 }
 
 void