Skip to content

Commit 6e7b152

Browse files
committed
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 f60d7e1)
1 parent 39d37ff commit 6e7b152

File tree

3 files changed

+8
-36
lines changed

3 files changed

+8
-36
lines changed

libstdc++-v3/include/std/string_view

-2
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
160160
&& (!requires (_DRange& __d) {
161161
__d.operator ::std::basic_string_view<_CharT, _Traits>();
162162
})
163-
&& (!requires { typename _DRange::traits_type; }
164-
|| is_same_v<typename _DRange::traits_type, _Traits>)
165163
constexpr explicit
166164
basic_string_view(_Range&& __r)
167165
noexcept(noexcept(ranges::size(__r)) && noexcept(ranges::data(__r)))

libstdc++-v3/testsuite/21_strings/basic_string_view/cons/char/range_c++20.cc

+4-17
Original file line numberDiff line numberDiff line change
@@ -116,23 +116,10 @@ test02()
116116
static_assert( ! std::is_constructible_v<std::string_view, V1> );
117117

118118
using V2 = std::basic_string_view<char, __gnu_cxx::char_traits<char>>;
119-
// V2::traits_type is not the right type
120-
static_assert( ! std::is_constructible_v<std::string_view, V2> );
121-
122-
struct V3 : V2
123-
{
124-
private:
125-
using V2::traits_type;
126-
};
127-
// V3::traits_type is not a valid (accessible) type
128-
static_assert( std::is_constructible_v<std::string_view, V3> );
129-
130-
struct V4 : V2
131-
{
132-
using traits_type = std::string_view::traits_type;
133-
};
134-
// V4::traits_type is the right type
135-
static_assert( std::is_constructible_v<std::string_view, V4> );
119+
// LWG 3857
120+
// basic_string_view should allow explicit conversion when only traits vary
121+
static_assert( std::is_constructible_v<std::string_view, V2> );
122+
static_assert( ! std::is_convertible_v<V2, std::string_view> );
136123
}
137124

138125
void

libstdc++-v3/testsuite/21_strings/basic_string_view/cons/wchar_t/range_c++20.cc

+4-17
Original file line numberDiff line numberDiff line change
@@ -116,23 +116,10 @@ test02()
116116
static_assert( ! std::is_constructible_v<std::wstring_view, V1> );
117117

118118
using V2 = std::basic_string_view<wchar_t, __gnu_cxx::char_traits<wchar_t>>;
119-
// V2::traits_type is not the right type
120-
static_assert( ! std::is_constructible_v<std::wstring_view, V2> );
121-
122-
struct V3 : V2
123-
{
124-
private:
125-
using V2::traits_type;
126-
};
127-
// V3::traits_type is not a valid (accessible) type
128-
static_assert( std::is_constructible_v<std::wstring_view, V3> );
129-
130-
struct V4 : V2
131-
{
132-
using traits_type = std::wstring_view::traits_type;
133-
};
134-
// V4::traits_type is the right type
135-
static_assert( std::is_constructible_v<std::wstring_view, V4> );
119+
// LWG 3857
120+
// basic_string_view should allow explicit conversion when only traits vary
121+
static_assert( std::is_constructible_v<std::wstring_view, V2> );
122+
static_assert( ! std::is_convertible_v<V2, std::wstring_view> );
136123
}
137124

138125
void

0 commit comments

Comments
 (0)