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.geiss...@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.

commit 98afe2e1a9ee322885ce526f3df6ee612566da96
Author: Jonathan Wakely <jwak...@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>

Reply via email to