From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 0F3363858432; Mon, 8 Apr 2024 16:45:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0F3363858432 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1712594723; bh=rb2h0eltOijirbI80Mqt6XS9+9CiBcVJA30y9Snbh3A=; h=From:To:Subject:Date:From; b=Oppfhtn9UUuXtAalimBWLmGSx3IoedjzTrotE08nt5ASptj0zGPyhKdnEPpkfz9eI JrGmjcoUGcfHAfan5vVWJyoEm/oD3XUqishkNp+hP5co9hmK7/WUXXQKFqewr9rTju itvgXwjw12SRULXvdt6U2p3kez+xByLLFD2if+/8= MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r14-9839] libstdc++: Use char for _Utf8_view if char8_t isn't available [PR114519] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: cd77e152875d3bc9c8966fc20241d73aa47532b3 X-Git-Newrev: feb6a2d3569095706170c9400e93add27a66e034 Message-Id: <20240408164523.0F3363858432@sourceware.org> Date: Mon, 8 Apr 2024 16:45:23 +0000 (GMT) List-Id: https://gcc.gnu.org/g:feb6a2d3569095706170c9400e93add27a66e034 commit r14-9839-gfeb6a2d3569095706170c9400e93add27a66e034 Author: Jonathan Wakely Date: Tue Apr 2 22:46:55 2024 +0100 libstdc++: Use char for _Utf8_view if char8_t isn't available [PR114519] Instead of just omitting the definition of __unicode::_Utf8_view when char8_t is disabled, we can make it use char instead. libstdc++-v3/ChangeLog: PR libstdc++/114519 * include/bits/unicode.h (_Utf8_view) [!__cpp_char8_t]: Define using char instead of char8_t. * testsuite/ext/unicode/view.cc: Use u8""sv literals to create string views, instead of std::u8string_view. Diff: --- libstdc++-v3/include/bits/unicode.h | 3 +++ libstdc++-v3/testsuite/ext/unicode/view.cc | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/include/bits/unicode.h b/libstdc++-v3/include/bits/unicode.h index 0e95c86a0b0..29813b743dc 100644 --- a/libstdc++-v3/include/bits/unicode.h +++ b/libstdc++-v3/include/bits/unicode.h @@ -581,6 +581,9 @@ namespace __unicode #ifdef __cpp_char8_t template using _Utf8_view = _Utf_view; +#else + template + using _Utf8_view = _Utf_view; #endif template using _Utf16_view = _Utf_view; diff --git a/libstdc++-v3/testsuite/ext/unicode/view.cc b/libstdc++-v3/testsuite/ext/unicode/view.cc index 79ea2bbc6b7..ee23b0b1d8a 100644 --- a/libstdc++-v3/testsuite/ext/unicode/view.cc +++ b/libstdc++-v3/testsuite/ext/unicode/view.cc @@ -10,7 +10,7 @@ using namespace std::string_view_literals; constexpr void test_utf8_to_utf8() { - const std::u8string_view s8 = u8"£🇬🇧 €🇪🇺 æбçδé ♠♥♦♣ 🤡"; + const auto s8 = u8"£🇬🇧 €🇪🇺 æбçδé ♠♥♦♣ 🤡"sv; uc::_Utf8_view v(s8); VERIFY( std::ranges::distance(v) == s8.size() ); VERIFY( std::ranges::equal(v, s8) ); @@ -19,7 +19,7 @@ test_utf8_to_utf8() constexpr void test_utf8_to_utf16() { - const std::u8string_view s8 = u8"£🇬🇧 €🇪🇺 æбçδé ♠♥♦♣ 🤡"; + const auto s8 = u8"£🇬🇧 €🇪🇺 æбçδé ♠♥♦♣ 🤡"sv; const std::u16string_view s16 = u"£🇬🇧 €🇪🇺 æбçδé ♠♥♦♣ 🤡"; uc::_Utf16_view v(s8); VERIFY( std::ranges::distance(v) == s16.size() );