]> gcc.gnu.org Git - gcc.git/commitdiff
libstdc++: Define type traits for wchar_t even when libc support missing
authorJonathan Wakely <jwakely@redhat.com>
Sun, 1 Nov 2020 10:56:36 +0000 (10:56 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Sun, 1 Nov 2020 11:39:07 +0000 (11:39 +0000)
This meets the requirement that std::is_integral_v<wchar_t> is true,
even when full library support for wchar_t via specializations of
char_traits etc. is not provided. This is done by checking
__WCHAR_TYPE__ to see if the compiler knows about the type, rather than
checking the library's own _GLIBCXX_USE_WCHAR_T autoconf macro.

This assumes that the C++ compiler correctly defines wchar_t as a
distinct type, not a typedef for one of the other integeral types. This
is always true for G++ and should be true for any supported non-GNU
compilers.

Similarly, the std::make_unsigned and std::make_signed traits and the
internal helpers std::__is_integer and std::__is_char are also changed
to depend on the same macro.

libstdc++-v3/ChangeLog:

* include/std/type_traits (is_integral<wchar_t>)
(make_unsigned<wchar_t>, make_signed<wchar_t>): Define based
on #ifdef __WCHAR_TYPE__ instead of _GLIBCXX_USE_WCHAR_T.
* include/bits/cpp_type_traits.h (__is_integer<wchar_t>)
(__is_char<wchar_t>): Likewise.

libstdc++-v3/include/bits/cpp_type_traits.h
libstdc++-v3/include/std/type_traits

index b48d1adc63c9532e6ceb1a149869445f69aa0f39..433a2d7d35bc756b8bd68bd897c614cd42b2539d 100644 (file)
@@ -162,7 +162,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       typedef __true_type __type;
     };
 
-# ifdef _GLIBCXX_USE_WCHAR_T
+# ifdef __WCHAR_TYPE__
   template<>
     struct __is_integer<wchar_t>
     {
@@ -363,7 +363,7 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3)
       typedef __true_type __type;
     };
 
-#ifdef _GLIBCXX_USE_WCHAR_T
+#ifdef __WCHAR_TYPE__
   template<>
     struct __is_char<wchar_t>
     {
index e9a0f55dd4a8cfe841e1dc909995b51bffa5ca30..34e068b59523f0e532f52500a7b8714717e0ca34 100644 (file)
@@ -269,7 +269,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     struct __is_integral_helper<unsigned char>
     : public true_type { };
 
-#ifdef _GLIBCXX_USE_WCHAR_T
+  // We want is_integral<wchar_t> to be true (and make_signed/unsigned to work)
+  // even when libc doesn't provide working <wchar.h> and related functions,
+  // so check __WCHAR_TYPE__ instead of _GLIBCXX_USE_WCHAR_T.
+#ifdef __WCHAR_TYPE__
   template<>
     struct __is_integral_helper<wchar_t>
     : public true_type { };
@@ -1742,7 +1745,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // neither signed integer types nor unsigned integer types, so must be
   // transformed to the unsigned integer type with the smallest rank.
   // Use the partial specialization for enumeration types to do that.
-#if defined(_GLIBCXX_USE_WCHAR_T)
+#ifdef __WCHAR_TYPE__
   template<>
     struct __make_unsigned<wchar_t>
     {
@@ -1868,7 +1871,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // signed integer types nor unsigned integer types, so must be
   // transformed to the signed integer type with the smallest rank.
   // Use the partial specialization for enumeration types to do that.
-#if defined(_GLIBCXX_USE_WCHAR_T)
+#if defined(__WCHAR_TYPE__)
   template<>
     struct __make_signed<wchar_t>
     {
This page took 0.067953 seconds and 5 git commands to generate.