From patchwork Sat Oct 9 00:13:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 46022 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 02A9D3857C5B for ; Sat, 9 Oct 2021 00:17:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 02A9D3857C5B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1633738667; bh=vxMSFtUhmTS2yjHbO4L5tr+MlhJlxvGMcfM8TbIrUc8=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=bVS34XDD0nJe8cSsgp0bX5+WyIT2/Ftt1z+F5YMt4dykgUBgUx9F6KvYE2BgNw74I kEX/+KLIT/Ow1YzNrbZYR+mSEHxD08UMWcNVMT77OKJtMh+Y0yIz4C3uln+5F8iAX2 J8IBe22maXwwzKtyQ32ISi8YaznwVLRtgvaJnNNc= 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.133.124]) by sourceware.org (Postfix) with ESMTP id B58293857C72 for ; Sat, 9 Oct 2021 00:14:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B58293857C72 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-246-kDKTYuUKPNmPjnWxvgWrWA-1; Fri, 08 Oct 2021 20:13:55 -0400 X-MC-Unique: kDKTYuUKPNmPjnWxvgWrWA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 06D021006AA2; Sat, 9 Oct 2021 00:13:55 +0000 (UTC) Received: from localhost (unknown [10.33.37.44]) by smtp.corp.redhat.com (Postfix) with ESMTP id AC16260622; Sat, 9 Oct 2021 00:13:54 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH 3/8] libstdc++: Always define typedefs and hash functions for wide strings [PR 98725] Date: Sat, 9 Oct 2021 01:13:46 +0100 Message-Id: <20211009001351.659647-3-jwakely@redhat.com> In-Reply-To: <20211009001351.659647-1-jwakely@redhat.com> References: <20211009001351.659647-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" The wstring and wstring_view typedefs should be enabled even if isn't supported, because char_traits works unconditionally. Similarly, the std::hash specializations for wide strings do not depend on support. Although the primary template works OK for std::char_traits in the absence of support, this patch still defines it as an explicit specialization for compatibility with declarations that expect it to be specialized. The explicit specialization just uses the same __gnu_cxx::char_traits base class as the primary template. libstdc++-v3/ChangeLog: PR libstdc++/98725 * include/bits/char_traits.h (char_traits): Define explicit specialization unconditionally. * include/bits/basic_string.h (hash): Define unconditionally. Do not check _GLIBCXX_USE_WCHAR_T. * include/bits/stringfwd.h (wstring): Likewise. * include/debug/string (wstring): Likewise. * include/experimental/string_view (experimental::wstring_view) (hash): Likewise. * include/std/string (pmr::wstring, hash): Likewise. * include/std/string_view (wstring_view, hash): Likewise. --- libstdc++-v3/include/bits/basic_string.h | 4 ---- libstdc++-v3/include/bits/char_traits.h | 6 +++++- libstdc++-v3/include/bits/stringfwd.h | 4 ---- libstdc++-v3/include/debug/string | 2 -- libstdc++-v3/include/experimental/string_view | 6 ------ libstdc++-v3/include/std/string | 4 ---- libstdc++-v3/include/std/string_view | 6 ------ 7 files changed, 5 insertions(+), 27 deletions(-) diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index 68c388408f0..59c84b1b6ad 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -3954,7 +3954,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct __is_fast_hash> : std::false_type { }; -#ifdef _GLIBCXX_USE_WCHAR_T /// std::hash specialization for wstring. template<> struct hash @@ -3969,7 +3968,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<> struct __is_fast_hash> : std::false_type { }; -#endif #endif /* _GLIBCXX_COMPATIBILITY_CXX0X */ #ifdef _GLIBCXX_USE_CHAR8_T @@ -4034,12 +4032,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION operator""s(const char* __str, size_t __len) { return basic_string{__str, __len}; } -#ifdef _GLIBCXX_USE_WCHAR_T _GLIBCXX_DEFAULT_ABI_TAG inline basic_string operator""s(const wchar_t* __str, size_t __len) { return basic_string{__str, __len}; } -#endif #ifdef _GLIBCXX_USE_CHAR8_T _GLIBCXX_DEFAULT_ABI_TAG diff --git a/libstdc++-v3/include/bits/char_traits.h b/libstdc++-v3/include/bits/char_traits.h index 3da6e28a513..f6f8851c22d 100644 --- a/libstdc++-v3/include/bits/char_traits.h +++ b/libstdc++-v3/include/bits/char_traits.h @@ -256,7 +256,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * for advice on how to make use of this class for @a unusual character * types. Also, check out include/ext/pod_char_traits.h. */ - template + template struct char_traits : public __gnu_cxx::char_traits<_CharT> { }; @@ -507,6 +507,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION not_eof(const int_type& __c) _GLIBCXX_NOEXCEPT { return eq_int_type(__c, eof()) ? 0 : __c; } }; +#else // _GLIBCXX_USE_WCHAR_T + template<> + struct char_traits : public __gnu_cxx::char_traits + { }; #endif //_GLIBCXX_USE_WCHAR_T #ifdef _GLIBCXX_USE_CHAR8_T diff --git a/libstdc++-v3/include/bits/stringfwd.h b/libstdc++-v3/include/bits/stringfwd.h index 7cb92ebcbfe..bcfd350e505 100644 --- a/libstdc++-v3/include/bits/stringfwd.h +++ b/libstdc++-v3/include/bits/stringfwd.h @@ -54,9 +54,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<> struct char_traits; -#ifdef _GLIBCXX_USE_WCHAR_T template<> struct char_traits; -#endif #ifdef _GLIBCXX_USE_CHAR8_T template<> struct char_traits; @@ -78,10 +76,8 @@ _GLIBCXX_END_NAMESPACE_CXX11 /// A string of @c char typedef basic_string string; -#ifdef _GLIBCXX_USE_WCHAR_T /// A string of @c wchar_t typedef basic_string wstring; -#endif #ifdef _GLIBCXX_USE_CHAR8_T /// A string of @c char8_t diff --git a/libstdc++-v3/include/debug/string b/libstdc++-v3/include/debug/string index 8744a55be64..a8389528001 100644 --- a/libstdc++-v3/include/debug/string +++ b/libstdc++-v3/include/debug/string @@ -1298,9 +1298,7 @@ namespace __gnu_debug typedef basic_string string; -#ifdef _GLIBCXX_USE_WCHAR_T typedef basic_string wstring; -#endif #ifdef _GLIBCXX_USE_CHAR8_T /// A string of @c char8_t diff --git a/libstdc++-v3/include/experimental/string_view b/libstdc++-v3/include/experimental/string_view index d9bc5cd166d..b8e4db8ef30 100644 --- a/libstdc++-v3/include/experimental/string_view +++ b/libstdc++-v3/include/experimental/string_view @@ -564,9 +564,7 @@ inline namespace fundamentals_v1 // basic_string_view typedef names using string_view = basic_string_view; -#ifdef _GLIBCXX_USE_WCHAR_T using wstring_view = basic_string_view; -#endif #ifdef _GLIBCXX_USE_CHAR8_T using u8string_view = basic_string_view; #endif @@ -593,7 +591,6 @@ inline namespace fundamentals_v1 struct __is_fast_hash> : std::false_type { }; -#ifdef _GLIBCXX_USE_WCHAR_T template<> struct hash : public __hash_base @@ -607,7 +604,6 @@ inline namespace fundamentals_v1 template<> struct __is_fast_hash> : std::false_type { }; -#endif #ifdef _GLIBCXX_USE_CHAR8_T template<> @@ -665,11 +661,9 @@ namespace experimental operator""sv(const char* __str, size_t __len) noexcept { return basic_string_view{__str, __len}; } -#ifdef _GLIBCXX_USE_WCHAR_T inline constexpr basic_string_view operator""sv(const wchar_t* __str, size_t __len) noexcept { return basic_string_view{__str, __len}; } -#endif #ifdef _GLIBCXX_USE_CHAR8_T inline constexpr basic_string_view diff --git a/libstdc++-v3/include/std/string b/libstdc++-v3/include/std/string index 95412b6f7a3..af840e887d5 100644 --- a/libstdc++-v3/include/std/string +++ b/libstdc++-v3/include/std/string @@ -68,9 +68,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif using u16string = basic_string; using u32string = basic_string; -#ifdef _GLIBCXX_USE_WCHAR_T using wstring = basic_string; -#endif } // namespace pmr template @@ -100,12 +98,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct hash : public __hash_string_base { }; -#ifdef _GLIBCXX_USE_WCHAR_T template<> struct hash : public __hash_string_base { }; -#endif _GLIBCXX_END_NAMESPACE_VERSION } // namespace std diff --git a/libstdc++-v3/include/std/string_view b/libstdc++-v3/include/std/string_view index 996b03f9346..fd92df6e425 100644 --- a/libstdc++-v3/include/std/string_view +++ b/libstdc++-v3/include/std/string_view @@ -674,9 +674,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // basic_string_view typedef names using string_view = basic_string_view; -#ifdef _GLIBCXX_USE_WCHAR_T using wstring_view = basic_string_view; -#endif #ifdef _GLIBCXX_USE_CHAR8_T using u8string_view = basic_string_view; #endif @@ -701,7 +699,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct __is_fast_hash> : std::false_type { }; -#ifdef _GLIBCXX_USE_WCHAR_T template<> struct hash : public __hash_base @@ -715,7 +712,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<> struct __is_fast_hash> : std::false_type { }; -#endif #ifdef _GLIBCXX_USE_CHAR8_T template<> @@ -770,11 +766,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION operator""sv(const char* __str, size_t __len) noexcept { return basic_string_view{__str, __len}; } -#ifdef _GLIBCXX_USE_WCHAR_T inline constexpr basic_string_view operator""sv(const wchar_t* __str, size_t __len) noexcept { return basic_string_view{__str, __len}; } -#endif #ifdef _GLIBCXX_USE_CHAR8_T inline constexpr basic_string_view