public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Use __is_same_as for std::is_same and std::is_same_v
@ 2019-10-11 15:50 Jonathan Wakely
  2019-10-12 15:43 ` Romain Geissler
  0 siblings, 1 reply; 6+ messages in thread
From: Jonathan Wakely @ 2019-10-11 15:50 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 416 bytes --]

By using the built-in we don't need to match a partial specialization
for std::is_same and don't need to instantiate std::is_same at all for
uses of std::is_same_v.

	* include/std/type_traits (is_same): Replace partial specialization
	by using __is_same_as built-in in primary template.
	(is_same_v): Use __is_same_as built-in instead of instantiating the
	is_same trait.

Tested x86_64-linux, committed to trunk.


[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 1766 bytes --]

commit ee208e530893aeb12b6a9edb1563a4e8ecaea887
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Sep 11 21:23:31 2019 +0100

    Use __is_same_as for std::is_same and std::is_same_v
    
    By using the built-in we don't need to match a partial specialization
    for std::is_same and don't need to instantiate std::is_same at all for
    uses of std::is_same_v.
    
            * include/std/type_traits (is_same): Replace partial specialization
            by using __is_same_as built-in in primary template.
            (is_same_v): Use __is_same_as built-in instead of instantiating the
            is_same trait.

diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
index dc8a019324d..4de5daa9f06 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -1388,13 +1388,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // Type relations.
 
   /// is_same
-  template<typename, typename>
+  template<typename _Tp, typename _Up>
     struct is_same
-    : public false_type { };
-
-  template<typename _Tp>
-    struct is_same<_Tp, _Tp>
-    : public true_type { };
+    : public integral_constant<bool, __is_same_as(_Tp, _Up)>
+    { };
 
   /// is_base_of
   template<typename _Base, typename _Derived>
@@ -3158,7 +3155,7 @@ template <typename _Tp>
 template <typename _Tp, unsigned _Idx = 0>
   inline constexpr size_t extent_v = extent<_Tp, _Idx>::value;
 template <typename _Tp, typename _Up>
-  inline constexpr bool is_same_v = is_same<_Tp, _Up>::value;
+  inline constexpr bool is_same_v = __is_same_as(_Tp, _Up);
 template <typename _Base, typename _Derived>
   inline constexpr bool is_base_of_v = is_base_of<_Base, _Derived>::value;
 template <typename _From, typename _To>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Use __is_same_as for std::is_same and std::is_same_v
  2019-10-11 15:50 [PATCH] Use __is_same_as for std::is_same and std::is_same_v Jonathan Wakely
@ 2019-10-12 15:43 ` Romain Geissler
  2019-10-12 16:14   ` Romain Geissler
  0 siblings, 1 reply; 6+ messages in thread
From: Romain Geissler @ 2019-10-12 15:43 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: libstdc++, GCC Patches

Le ven. 11 oct. 2019 à 17:50, Jonathan Wakely <jwakely@redhat.com> a écrit :
>
> By using the built-in we don't need to match a partial specialization
> for std::is_same and don't need to instantiate std::is_same at all for
> uses of std::is_same_v.
>
>         * include/std/type_traits (is_same): Replace partial specialization
>         by using __is_same_as built-in in primary template.
>         (is_same_v): Use __is_same_as built-in instead of instantiating the
>         is_same trait.
>
> Tested x86_64-linux, committed to trunk.
>

Hi Jonathan,

It looks like this creates the following error when I try to bootstrap
clang 9.0.0 using the latest gcc and libstdc++ from trunk. Note that
with g++, there is no problem, however it looks like clang++ has some
problem with the new header. I don't know if this is an issue on
libstdc++ side or clang++ side.

Cheers,
Romain

FAILED: compiler-rt/lib/xray/CMakeFiles/RTXray.x86_64.dir/xray_buffer_queue.cc.o
/workdir/build/final-system/llvm-build/./bin/clang++
--target=x86_64-1a-linux-gnu  -DXRAY_HAS_EXCEPTIONS=1
-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
-I/workdir/src/llvm-9.0.0/compiler-rt/lib/xray/..
-I/workdir/src/llvm-9.0.0/compiler-rt/lib/xray/../../include -O2 -msse
-msse2 -msse3 -I/workdir/build/final-system/llvm-temporary-static-dependencies/install/include
-I/workdir/build/final-system/llvm-temporary-static-dependencies/install/include/ncursesw
-fvisibility-inlines-hidden -Werror=date-time
-Werror=unguarded-availability-new -std=c++11 -Wall -Wextra
-Wno-unused-parameter -Wwrite-strings -Wcast-qual
-Wmissing-field-initializers -Wimplicit-fallthrough
-Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor
-Wdelete-non-virtual-dtor -Wstring-conversion -fdiagnostics-color
-ffunction-sections -fdata-sections -Wall -std=c++11
-Wno-unused-parameter -O3 -DNDEBUG    -m64 -fPIC -fno-builtin
-fno-exceptions -fomit-frame-pointer -funwind-tables
-fno-stack-protector -fno-sanitize=safe-stack -fvisibility=hidden
-fno-lto -O3 -gline-tables-only -Wno-gnu -Wno-variadic-macros
-Wno-c99-extensions -Wno-non-virtual-dtor -fno-rtti -MD -MT
compiler-rt/lib/xray/CMakeFiles/RTXray.x86_64.dir/xray_buffer_queue.cc.o
-MF compiler-rt/lib/xray/CMakeFiles/RTXray.x86_64.dir/xray_buffer_queue.cc.o.d
-o compiler-rt/lib/xray/CMakeFiles/RTXray.x86_64.dir/xray_buffer_queue.cc.o
-c /workdir/src/llvm-9.0.0/compiler-rt/lib/xray/xray_buffer_queue.cc
In file included from
/workdir/src/llvm-9.0.0/compiler-rt/lib/xray/xray_buffer_queue.cc:21:
In file included from
/workdir/src/llvm-9.0.0/compiler-rt/lib/xray/xray_allocator.h:29:
In file included from
/workdir/src/llvm-9.0.0/compiler-rt/lib/xray/xray_utils.h:20:
In file included from
/opt/1A/toolchain/x86_64-v20.0.3/lib64/gcc/x86_64-1a-linux-gnu/10.0.0/../../../../include/c++/10.0.0/utility:70:
In file included from
/opt/1A/toolchain/x86_64-v20.0.3/lib64/gcc/x86_64-1a-linux-gnu/10.0.0/../../../../include/c++/10.0.0/bits/stl_pair.h:59:
In file included from
/opt/1A/toolchain/x86_64-v20.0.3/lib64/gcc/x86_64-1a-linux-gnu/10.0.0/../../../../include/c++/10.0.0/bits/move.h:55:
/opt/1A/toolchain/x86_64-v20.0.3/lib64/gcc/x86_64-1a-linux-gnu/10.0.0/../../../../include/c++/10.0.0/type_traits:1393:51:
error: '_Tp' does not refer to a value
    : public integral_constant<bool, __is_same_as(_Tp, _Up)>
                                                  ^
/opt/1A/toolchain/x86_64-v20.0.3/lib64/gcc/x86_64-1a-linux-gnu/10.0.0/../../../../include/c++/10.0.0/type_traits:1391:21:
note: declared here
  template<typename _Tp, typename _Up>
                    ^
/opt/1A/toolchain/x86_64-v20.0.3/lib64/gcc/x86_64-1a-linux-gnu/10.0.0/../../../../include/c++/10.0.0/type_traits:1393:56:
error: '_Up' does not refer to a value
    : public integral_constant<bool, __is_same_as(_Tp, _Up)>
                                                       ^
/opt/1A/toolchain/x86_64-v20.0.3/lib64/gcc/x86_64-1a-linux-gnu/10.0.0/../../../../include/c++/10.0.0/type_traits:1391:35:
note: declared here
  template<typename _Tp, typename _Up>
                                  ^
2 errors generated.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Use __is_same_as for std::is_same and std::is_same_v
  2019-10-12 15:43 ` Romain Geissler
@ 2019-10-12 16:14   ` Romain Geissler
  2019-10-16  9:42     ` Jonathan Wakely
  0 siblings, 1 reply; 6+ messages in thread
From: Romain Geissler @ 2019-10-12 16:14 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: libstdc++, GCC Patches

Le sam. 12 oct. 2019 à 17:44, Romain Geissler
<romain.geissler@gmail.com> a écrit :
>
> It looks like this creates the following error when I try to bootstrap
> clang 9.0.0 using the latest gcc and libstdc++ from trunk. Note that
> with g++, there is no problem, however it looks like clang++ has some
> problem with the new header. I don't know if this is an issue on
> libstdc++ side or clang++ side.

__is_same_as is not implemented as a compiler builtin in clang++
unlike g++, thus the error on clang 9.0.0 side. It looks like current
clang trunk doesn't define __is_same_as either. Until clang implements
this support (if it ever will), usage of __is_same_as in libstdc++
shall be conditional, only when __has_builtin(__is_same_as) is true
(however that would require that gcc implements __has_builtin, as
implemented here:
https://gcc.gnu.org/ml/gcc-patches/2019-10/msg00062.html )

Cheers,
Romain

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Use __is_same_as for std::is_same and std::is_same_v
  2019-10-12 16:14   ` Romain Geissler
@ 2019-10-16  9:42     ` Jonathan Wakely
  2019-10-16  9:43       ` Jonathan Wakely
  0 siblings, 1 reply; 6+ messages in thread
From: Jonathan Wakely @ 2019-10-16  9:42 UTC (permalink / raw)
  To: Romain Geissler; +Cc: libstdc++, GCC Patches

On 12/10/19 18:15 +0200, Romain Geissler wrote:
>Le sam. 12 oct. 2019 à 17:44, Romain Geissler
><romain.geissler@gmail.com> a écrit :
>>
>> It looks like this creates the following error when I try to bootstrap
>> clang 9.0.0 using the latest gcc and libstdc++ from trunk. Note that
>> with g++, there is no problem, however it looks like clang++ has some
>> problem with the new header. I don't know if this is an issue on
>> libstdc++ side or clang++ side.
>
>__is_same_as is not implemented as a compiler builtin in clang++

Sigh, I guess that explains why we weren't using it already.

>unlike g++, thus the error on clang 9.0.0 side. It looks like current
>clang trunk doesn't define __is_same_as either. Until clang implements
>this support (if it ever will), usage of __is_same_as in libstdc++
>shall be conditional, only when __has_builtin(__is_same_as) is true
>(however that would require that gcc implements __has_builtin, as
>implemented here:
>https://gcc.gnu.org/ml/gcc-patches/2019-10/msg00062.html )

No, we don't need GCC to support __has_builtin, because we know GCC
supports __is_same_as so there's no need to check for it.

So something like this would work fine:

#if __GNUC__ >= 10
# define _GLIBCXX_HAVE__IS_SAME_AS
#elif defined(__has_builtin)
# if __has_builtin(__is_same_as)
#  define _GLIBCXX_HAVE__IS_SAME_AS
# endif
#endif



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Use __is_same_as for std::is_same and std::is_same_v
  2019-10-16  9:42     ` Jonathan Wakely
@ 2019-10-16  9:43       ` Jonathan Wakely
  2019-10-16 10:26         ` Jonathan Wakely
  0 siblings, 1 reply; 6+ messages in thread
From: Jonathan Wakely @ 2019-10-16  9:43 UTC (permalink / raw)
  To: Romain Geissler; +Cc: libstdc++, GCC Patches

On 16/10/19 10:42 +0100, Jonathan Wakely wrote:
>On 12/10/19 18:15 +0200, Romain Geissler wrote:
>>Le sam. 12 oct. 2019 à 17:44, Romain Geissler
>><romain.geissler@gmail.com> a écrit :
>>>
>>>It looks like this creates the following error when I try to bootstrap
>>>clang 9.0.0 using the latest gcc and libstdc++ from trunk. Note that
>>>with g++, there is no problem, however it looks like clang++ has some
>>>problem with the new header. I don't know if this is an issue on
>>>libstdc++ side or clang++ side.
>>
>>__is_same_as is not implemented as a compiler builtin in clang++
>
>Sigh, I guess that explains why we weren't using it already.
>
>>unlike g++, thus the error on clang 9.0.0 side. It looks like current
>>clang trunk doesn't define __is_same_as either. Until clang implements
>>this support (if it ever will), usage of __is_same_as in libstdc++
>>shall be conditional, only when __has_builtin(__is_same_as) is true
>>(however that would require that gcc implements __has_builtin, as
>>implemented here:
>>https://gcc.gnu.org/ml/gcc-patches/2019-10/msg00062.html )
>
>No, we don't need GCC to support __has_builtin, because we know GCC
>supports __is_same_as so there's no need to check for it.
>
>So something like this would work fine:
>
>#if __GNUC__ >= 10
># define _GLIBCXX_HAVE__IS_SAME_AS
>#elif defined(__has_builtin)
># if __has_builtin(__is_same_as)
>#  define _GLIBCXX_HAVE__IS_SAME_AS
># endif
>#endif

It looks like Clang provides __is_same instead.

I'll commit a fix today.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Use __is_same_as for std::is_same and std::is_same_v
  2019-10-16  9:43       ` Jonathan Wakely
@ 2019-10-16 10:26         ` Jonathan Wakely
  0 siblings, 0 replies; 6+ messages in thread
From: Jonathan Wakely @ 2019-10-16 10:26 UTC (permalink / raw)
  To: Romain Geissler; +Cc: libstdc++, GCC Patches

[-- Attachment #1: Type: text/plain, Size: 1739 bytes --]

On 16/10/19 10:43 +0100, Jonathan Wakely wrote:
>On 16/10/19 10:42 +0100, Jonathan Wakely wrote:
>>On 12/10/19 18:15 +0200, Romain Geissler wrote:
>>>Le sam. 12 oct. 2019 à 17:44, Romain Geissler
>>><romain.geissler@gmail.com> a écrit :
>>>>
>>>>It looks like this creates the following error when I try to bootstrap
>>>>clang 9.0.0 using the latest gcc and libstdc++ from trunk. Note that
>>>>with g++, there is no problem, however it looks like clang++ has some
>>>>problem with the new header. I don't know if this is an issue on
>>>>libstdc++ side or clang++ side.
>>>
>>>__is_same_as is not implemented as a compiler builtin in clang++
>>
>>Sigh, I guess that explains why we weren't using it already.
>>
>>>unlike g++, thus the error on clang 9.0.0 side. It looks like current
>>>clang trunk doesn't define __is_same_as either. Until clang implements
>>>this support (if it ever will), usage of __is_same_as in libstdc++
>>>shall be conditional, only when __has_builtin(__is_same_as) is true
>>>(however that would require that gcc implements __has_builtin, as
>>>implemented here:
>>>https://gcc.gnu.org/ml/gcc-patches/2019-10/msg00062.html )
>>
>>No, we don't need GCC to support __has_builtin, because we know GCC
>>supports __is_same_as so there's no need to check for it.
>>
>>So something like this would work fine:
>>
>>#if __GNUC__ >= 10
>># define _GLIBCXX_HAVE__IS_SAME_AS
>>#elif defined(__has_builtin)
>># if __has_builtin(__is_same_as)
>>#  define _GLIBCXX_HAVE__IS_SAME_AS
>># endif
>>#endif
>
>It looks like Clang provides __is_same instead.
>
>I'll commit a fix today.

This is what I've committed to trunk, after testing on x86_64-linux,
and checking it with Clang.

Thanks for testing and reporting the problem.


[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 3999 bytes --]

commit 98afe2e1a9ee322885ce526f3df6ee612566da96
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Oct 16 11:00:17 2019 +0100

    Only use GCC-specific __is_same_as built-in conditionally
    
    Clang doesn't support __is_same_as but provides __is_same instead.
    Restore the original implementation (pre r276891) when neither of those
    built-ins is available.
    
            * include/bits/c++config (_GLIBCXX_BUILTIN_IS_SAME_AS): Define to
            one of __is_same_as or __is_same when available.
            * include/std/concepts (__detail::__same_as): Use std::is_same_v.
            * include/std/type_traits (is_same) [_GLIBCXX_BUILTIN_IS_SAME_AS]:
            Use new macro instead of __is_same_as.
            (is_same) [!_GLIBCXX_BUILTIN_IS_SAME_AS]: Restore partial
            specialization.
            (is_same_v) [_GLIBCXX_BUILTIN_IS_SAME_AS]: Use new macro.
            (is_same_v) [!_GLIBCXX_BUILTIN_IS_SAME_AS]: Use std::is_same.

diff --git a/libstdc++-v3/include/bits/c++config b/libstdc++-v3/include/bits/c++config
index c8e099aaadd..32db60f39e5 100644
--- a/libstdc++-v3/include/bits/c++config
+++ b/libstdc++-v3/include/bits/c++config
@@ -633,6 +633,7 @@ namespace std
 # define _GLIBCXX_HAVE_BUILTIN_HAS_UNIQ_OBJ_REP 1
 # define _GLIBCXX_HAVE_BUILTIN_IS_AGGREGATE 1
 # define _GLIBCXX_HAVE_BUILTIN_LAUNDER 1
+# define _GLIBCXX_BUILTIN_IS_SAME_AS(T, U) __is_same_as(T, U)
 # if __GNUC__ >= 9
 #  define _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED 1
 # endif
@@ -650,6 +651,9 @@ namespace std
 # if __has_builtin(__builtin_is_constant_evaluated)
 #  define _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED 1
 # endif
+# if ! __is_identifier(__is_same)
+#  define _GLIBCXX_BUILTIN_IS_SAME_AS(T, U) __is_same(T, U)
+# endif
 #endif // GCC
 
 // PSTL configuration
diff --git a/libstdc++-v3/include/std/concepts b/libstdc++-v3/include/std/concepts
index 6b1150a32d2..6d740eb663c 100644
--- a/libstdc++-v3/include/std/concepts
+++ b/libstdc++-v3/include/std/concepts
@@ -23,7 +23,7 @@
 // <http://www.gnu.org/licenses/>.
 
 /** @file include/concepts
- *  This is __a Standard C++ Library header.
+ *  This is a Standard C++ Library header.
  *  @ingroup concepts
  */
 
@@ -54,7 +54,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   namespace __detail
   {
     template<typename _Tp, typename _Up>
-      concept __same_as = __is_same_as(_Tp, _Up);
+      concept __same_as = std::is_same_v<_Tp, _Up>;
   } // namespace __detail
 
   /// [concept.same], concept same_as
diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
index 4de5daa9f06..8e787a994c3 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -1390,9 +1390,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   /// is_same
   template<typename _Tp, typename _Up>
     struct is_same
-    : public integral_constant<bool, __is_same_as(_Tp, _Up)>
+#ifdef _GLIBCXX_BUILTIN_IS_SAME_AS
+    : public integral_constant<bool, _GLIBCXX_BUILTIN_IS_SAME_AS(_Tp, _Up)>
+#else
+    : public false_type
+#endif
     { };
 
+#ifndef _GLIBCXX_BUILTIN_IS_SAME_AS
+  template<typename _Tp>
+    struct is_same<_Tp, _Tp>
+    : public true_type
+    { };
+#endif
+
   /// is_base_of
   template<typename _Base, typename _Derived>
     struct is_base_of
@@ -3154,8 +3165,13 @@ template <typename _Tp>
   inline constexpr size_t rank_v = rank<_Tp>::value;
 template <typename _Tp, unsigned _Idx = 0>
   inline constexpr size_t extent_v = extent<_Tp, _Idx>::value;
+#ifdef _GLIBCXX_BUILTIN_IS_SAME_AS
 template <typename _Tp, typename _Up>
-  inline constexpr bool is_same_v = __is_same_as(_Tp, _Up);
+  inline constexpr bool is_same_v = _GLIBCXX_BUILTIN_IS_SAME_AS(_Tp, _Up);
+#else
+template <typename _Tp, typename _Up>
+  inline constexpr bool is_same_v = std::is_same<_Tp, _Up>::value;
+#endif
 template <typename _Base, typename _Derived>
   inline constexpr bool is_base_of_v = is_base_of<_Base, _Derived>::value;
 template <typename _From, typename _To>

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-10-16 10:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-11 15:50 [PATCH] Use __is_same_as for std::is_same and std::is_same_v Jonathan Wakely
2019-10-12 15:43 ` Romain Geissler
2019-10-12 16:14   ` Romain Geissler
2019-10-16  9:42     ` Jonathan Wakely
2019-10-16  9:43       ` Jonathan Wakely
2019-10-16 10:26         ` Jonathan Wakely

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).