From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id A80063857C51; Fri, 2 Feb 2024 10:24:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A80063857C51 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1706869463; bh=qMn4Fy60vfqKccmZPrWj+4z0DjKVdj4unZO9o8MC31g=; h=From:To:Subject:Date:From; b=B6tXVCHQG+P+6YU15wxM1Oot+MGbUy2g6snFuzlNbKDNcjjLUN5BwiHA41kQATK+E +RIF44zI3OYxLsv6E6ZneXd3xCRMP+L+WnWjMyO7yzX7PUQh16zFrmeEyD2CdHse38 F+GG776J27cdFGVgr7BTRtJQvfPshNn4GI+C7E/Q= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r14-8740] libstdc++: Allow explicit conversion of string views with different traits X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: 67f5a8c802463228da7c7bb2ab100095217560a6 X-Git-Newrev: f60d7e1c64518936797ec1009cb49f72f8fe45b9 Message-Id: <20240202102423.A80063857C51@sourceware.org> Date: Fri, 2 Feb 2024 10:24:23 +0000 (GMT) List-Id: https://gcc.gnu.org/g:f60d7e1c64518936797ec1009cb49f72f8fe45b9 commit r14-8740-gf60d7e1c64518936797ec1009cb49f72f8fe45b9 Author: Jonathan Wakely Date: Thu Feb 1 21:40:33 2024 +0000 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. Diff: --- libstdc++-v3/include/std/string_view | 2 -- .../basic_string_view/cons/char/range_c++20.cc | 21 ++++----------------- .../basic_string_view/cons/wchar_t/range_c++20.cc | 21 ++++----------------- 3 files changed, 8 insertions(+), 36 deletions(-) diff --git a/libstdc++-v3/include/std/string_view b/libstdc++-v3/include/std/string_view index b444b5b9a39b..e30a9c1768e0 100644 --- a/libstdc++-v3/include/std/string_view +++ b/libstdc++-v3/include/std/string_view @@ -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) 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 5d0396563fd8..bae8da1d2645 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 @@ -115,23 +115,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 d6996a1dd6f0..3cf154d8602d 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 @@ -115,23 +115,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