From patchwork Mon Apr 8 16:45:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1920949 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=QwyBIdzx; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VCw4j4z3Gz1yY8 for ; Tue, 9 Apr 2024 02:47:49 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 452D13858CDA for ; Mon, 8 Apr 2024 16:47:47 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 6084D386101D for ; Mon, 8 Apr 2024 16:47:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6084D386101D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6084D386101D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712594846; cv=none; b=MDfc4umqOBRRk2EKAqjFVLy83MX6cZ0idzpRMDOT0PjNyqra0ICKtUOsG0CXfTOsp2ikUowSlz/dRkO5WR+i1eKu2yZ40cvUUCiQZYlLMArrrpFi6+dKRWnklO68+dBb7y9rbns8q+HvZX+hZAERqXB63Dg7FiyxBbqtNcXdmlU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712594846; c=relaxed/simple; bh=v0Nc1S7xqO8ppxIY5Wf3TNoclDUItfMnm9QvPdIpb2c=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=P4H7iWhlKMZBLURxbHtlxeMZ0I5mz4su2PpPmHS+XmkjTx7duWGmZhzjFn0PJu0GPci7yCKwJ9uzDoS35UXCKNrO2EN0zrcCNDxu4Dk5df/gZZsKjWUfaQO1Hb9YTtb5V/+FXtYlEUiyATDFDxho7zLviS+dcR0epEgtOozveKU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712594845; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=UsB0Cg6FnRMR6gR5fRY5On+5TTn4m7I3U4qNhwDGKOw=; b=QwyBIdzxdCK5F9cZ2Zi701CrAmFHRkDxB6dUUtWp8tUb4EGrV82mdY/ksxKF0b6crGdM3X j0brfnWC5Nxv1l0hBSzCZV8mg+1T24yVP/vllIibHeFh+T41PI+6gBuVJL8MnsRiIecC0+ GbjICWca4wiGLjeJfiYag4+x8pSlMVk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-679-AiuXeVznNkepLPaTCVA9XQ-1; Mon, 08 Apr 2024 12:47:23 -0400 X-MC-Unique: AiuXeVznNkepLPaTCVA9XQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1E16B801FAF; Mon, 8 Apr 2024 16:47:23 +0000 (UTC) Received: from localhost (unknown [10.42.28.163]) by smtp.corp.redhat.com (Postfix) with ESMTP id E2089920; Mon, 8 Apr 2024 16:47:22 +0000 (UTC) From: Jonathan Wakely 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 Message-ID: <20240408164702.196538-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, BODY_8BITS, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, PP_MIME_FAKE_ASCII_TEXT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 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() );