From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed] libstdc++: Use char for _Utf8_view if char8_t isn't available [PR114519]
Date: Mon, 8 Apr 2024 17:45:47 +0100 [thread overview]
Message-ID: <20240408164702.196538-1-jwakely@redhat.com> (raw)
I recently disabled _Utf8_view for -fno-char8_t, but we can just make it
use char instead of char8_t. The existing uses of it in the library are
unaffected.
Tested x86_64-linux and aarch64-linux. Pushed to trunk.
-- >8 --
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.
---
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<typename _View>
using _Utf8_view = _Utf_view<char8_t, _View>;
+#else
+ template<typename _View>
+ using _Utf8_view = _Utf_view<char, _View>;
#endif
template<typename _View>
using _Utf16_view = _Utf_view<char16_t, _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() );
--
2.44.0
reply other threads:[~2024-04-08 16:47 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240408164702.196538-1-jwakely@redhat.com \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).