public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
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	[thread overview]
Message-ID: <20211009001351.659647-3-jwakely@redhat.com> (raw)
In-Reply-To: <20211009001351.659647-1-jwakely@redhat.com>

The wstring and wstring_view typedefs should be enabled even if
<wchar.h> isn't supported, because char_traits<wchar_t> works
unconditionally. Similarly, the std::hash specializations for wide
strings do not depend on <wchar.h> support.

Although the primary template works OK for std::char_traits<wchar_t> in
the absence of <wchar.h> 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<wchar_t>): Define
	explicit specialization unconditionally.
	* include/bits/basic_string.h (hash<wstring>): 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<experimental::wstring_view>): Likewise.
	* include/std/string (pmr::wstring, hash<pmr::wstring>):
	Likewise.
	* include/std/string_view (wstring_view, hash<wstring_view>):
	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<hash<string>> : std::false_type
     { };
 
-#ifdef _GLIBCXX_USE_WCHAR_T
   /// std::hash specialization for wstring.
   template<>
     struct hash<wstring>
@@ -3969,7 +3968,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template<>
     struct __is_fast_hash<hash<wstring>> : 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<char>{__str, __len}; }
 
-#ifdef _GLIBCXX_USE_WCHAR_T
     _GLIBCXX_DEFAULT_ABI_TAG
     inline basic_string<wchar_t>
     operator""s(const wchar_t* __str, size_t __len)
     { return basic_string<wchar_t>{__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<class _CharT>
+  template<typename _CharT>
     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<wchar_t> : public __gnu_cxx::char_traits<wchar_t>
+    { };
 #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<char>;
 
-#ifdef _GLIBCXX_USE_WCHAR_T
   template<> struct char_traits<wchar_t>;
-#endif
 
 #ifdef _GLIBCXX_USE_CHAR8_T
   template<> struct char_traits<char8_t>;
@@ -78,10 +76,8 @@ _GLIBCXX_END_NAMESPACE_CXX11
   /// A string of @c char
   typedef basic_string<char>    string;   
 
-#ifdef _GLIBCXX_USE_WCHAR_T
   /// A string of @c wchar_t
   typedef basic_string<wchar_t> 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<char>    string;
 
-#ifdef _GLIBCXX_USE_WCHAR_T
   typedef basic_string<wchar_t> 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<char>;
-#ifdef _GLIBCXX_USE_WCHAR_T
   using wstring_view = basic_string_view<wchar_t>;
-#endif
 #ifdef _GLIBCXX_USE_CHAR8_T
   using u8string_view = basic_string_view<char8_t>;
 #endif
@@ -593,7 +591,6 @@ inline namespace fundamentals_v1
     struct __is_fast_hash<hash<experimental::string_view>> : std::false_type
     { };
 
-#ifdef _GLIBCXX_USE_WCHAR_T
   template<>
     struct hash<experimental::wstring_view>
     : public __hash_base<size_t, wstring>
@@ -607,7 +604,6 @@ inline namespace fundamentals_v1
   template<>
     struct __is_fast_hash<hash<experimental::wstring_view>> : 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<char>{__str, __len}; }
 
-#ifdef _GLIBCXX_USE_WCHAR_T
     inline constexpr basic_string_view<wchar_t>
     operator""sv(const wchar_t* __str, size_t __len) noexcept
     { return basic_string_view<wchar_t>{__str, __len}; }
-#endif
 
 #ifdef _GLIBCXX_USE_CHAR8_T
     inline constexpr basic_string_view<char8_t>
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<char16_t>;
     using u32string = basic_string<char32_t>;
-#ifdef _GLIBCXX_USE_WCHAR_T
     using wstring   = basic_string<wchar_t>;
-#endif
   } // namespace pmr
 
   template<typename _Str>
@@ -100,12 +98,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     struct hash<pmr::u32string>
     : public __hash_string_base<pmr::u32string>
     { };
-#ifdef _GLIBCXX_USE_WCHAR_T
   template<>
     struct hash<pmr::wstring>
     : public __hash_string_base<pmr::wstring>
     { };
-#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<char>;
-#ifdef _GLIBCXX_USE_WCHAR_T
   using wstring_view = basic_string_view<wchar_t>;
-#endif
 #ifdef _GLIBCXX_USE_CHAR8_T
   using u8string_view = basic_string_view<char8_t>;
 #endif
@@ -701,7 +699,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     struct __is_fast_hash<hash<string_view>> : std::false_type
     { };
 
-#ifdef _GLIBCXX_USE_WCHAR_T
   template<>
     struct hash<wstring_view>
     : public __hash_base<size_t, wstring_view>
@@ -715,7 +712,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template<>
     struct __is_fast_hash<hash<wstring_view>> : 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<char>{__str, __len}; }
 
-#ifdef _GLIBCXX_USE_WCHAR_T
     inline constexpr basic_string_view<wchar_t>
     operator""sv(const wchar_t* __str, size_t __len) noexcept
     { return basic_string_view<wchar_t>{__str, __len}; }
-#endif
 
 #ifdef _GLIBCXX_USE_CHAR8_T
     inline constexpr basic_string_view<char8_t>
-- 
2.31.1


  parent reply	other threads:[~2021-10-09  0:14 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-09  0:13 [committed 1/8] libstdc++: Add missing _GLIBCXX_USE_WCHAR_T checks in testsuite Jonathan Wakely
2021-10-09  0:13 ` [PATCH 2/8] libstdc++: Move test that depends on wchar_t I/O to wchar_t sub-directory Jonathan Wakely
2021-10-09  0:13 ` Jonathan Wakely [this message]
2021-10-09  0:13 ` [PATCH 4/8] libstdc++: Enable vstring for wchar_t unconditionally [PR98725] Jonathan Wakely
2021-10-09  0:13 ` [PATCH 5/8] libstdc++: Enable type traits " Jonathan Wakely
2021-10-09  0:13 ` [PATCH 6/8] libstdc++: Define std::wstring_convert unconditionally [PR 98725] Jonathan Wakely
2021-10-09  0:13 ` [PATCH 7/8] libstdc++: Define deleted wchar_t overloads " Jonathan Wakely
2021-10-09  0:13 ` [PATCH 8/8] libstdc++: Remove unnecessary uses of _GLIBCXX_USE_WCHAR_T in testsuite [PR98725] Jonathan Wakely

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=20211009001351.659647-3-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).