From 44af818f006a046ffadcfe39e7d475956ae55317 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Wed, 16 Oct 2019 11:26:05 +0100 Subject: [PATCH] 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. From-SVN: r277058 --- libstdc++-v3/ChangeLog | 12 ++++++++++++ libstdc++-v3/include/bits/c++config | 4 ++++ libstdc++-v3/include/std/concepts | 4 ++-- libstdc++-v3/include/std/type_traits | 20 ++++++++++++++++++-- 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 02b743414dd..c95aa32120b 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,15 @@ +2019-10-16 Jonathan Wakely + + * 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. + 2019-10-16 François Dumont * src/c++11/debug.cc (print_field): Replace constness_names 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 @@ // . /** @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 - 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 struct is_same - : public integral_constant +#ifdef _GLIBCXX_BUILTIN_IS_SAME_AS + : public integral_constant +#else + : public false_type +#endif { }; +#ifndef _GLIBCXX_BUILTIN_IS_SAME_AS + template + struct is_same<_Tp, _Tp> + : public true_type + { }; +#endif + /// is_base_of template struct is_base_of @@ -3154,8 +3165,13 @@ template inline constexpr size_t rank_v = rank<_Tp>::value; template inline constexpr size_t extent_v = extent<_Tp, _Idx>::value; +#ifdef _GLIBCXX_BUILTIN_IS_SAME_AS template - 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 + inline constexpr bool is_same_v = std::is_same<_Tp, _Up>::value; +#endif template inline constexpr bool is_base_of_v = is_base_of<_Base, _Derived>::value; template -- 2.30.2