[committed] libstdc++: Fix definition of std::remove_cvref_t

Message ID YJPkJQjiiXOEz/jI@redhat.com
State New
Headers show
Series
  • [committed] libstdc++: Fix definition of std::remove_cvref_t
Related show

Commit Message

Andreas Krebbel via Gcc-patches May 6, 2021, 12:42 p.m.
I originally defined std::remove_cvref_t in terms of the internal
__remove_cvref_t trait, to avoid instantiating the remove_cvref class
template. However, as described in P1715R0 that is observable by users
and is thus non-conforming.

This defines remove_cvref_t as specified in the standard.

libstdc++-v3/ChangeLog:

	* include/std/type_traits (remove_cvref_t): Define in terms of
	remove_cvref.
	* testsuite/20_util/remove_cvref/value.cc: Check alias.

Tested powerpc64le-linux. Committed to trunk.
commit 0e79e63026e43ad0577812ffb405dac8fa88af5b
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu May 6 13:40:53 2021

    libstdc++: Fix definition of std::remove_cvref_t
    
    I originally defined std::remove_cvref_t in terms of the internal
    __remove_cvref_t trait, to avoid instantiating the remove_cvref class
    template. However, as described in P1715R0 that is observable by users
    and is thus non-conforming.
    
    This defines remove_cvref_t as specified in the standard.
    
    libstdc++-v3/ChangeLog:
    
            * include/std/type_traits (remove_cvref_t): Define in terms of
            remove_cvref.
            * testsuite/20_util/remove_cvref/value.cc: Check alias.

Patch

diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
index 1f8b57b04a0..eaf06fcb036 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -3223,12 +3223,21 @@  template <typename _From, typename _To>
   /// Remove references and cv-qualifiers.
   template<typename _Tp>
     struct remove_cvref
-    {
-      using type = __remove_cvref_t<_Tp>;
-    };
+    : remove_cv<_Tp>
+    { };
 
   template<typename _Tp>
-    using remove_cvref_t = __remove_cvref_t<_Tp>;
+    struct remove_cvref<_Tp&>
+    : remove_cv<_Tp>
+    { };
+
+  template<typename _Tp>
+    struct remove_cvref<_Tp&&>
+    : remove_cv<_Tp>
+    { };
+
+  template<typename _Tp>
+    using remove_cvref_t = typename remove_cvref<_Tp>::type;
 
 #define __cpp_lib_type_identity 201806L
   /// Identity metafunction.
diff --git a/libstdc++-v3/testsuite/20_util/remove_cvref/value.cc b/libstdc++-v3/testsuite/20_util/remove_cvref/value.cc
index d4a28422977..a4f50d433dc 100644
--- a/libstdc++-v3/testsuite/20_util/remove_cvref/value.cc
+++ b/libstdc++-v3/testsuite/20_util/remove_cvref/value.cc
@@ -48,3 +48,10 @@  void test01()
   static_assert(is_same<typename remove_cvref<const int(&)()>::type,
 			const int()>::value, "");
 }
+
+// Declare using nested name of class template
+template<typename T> T func(typename std::remove_cvref<T>::type);
+// Define using alias
+template<typename T> T func(std::remove_cvref_t<T> t) { return t; }
+// Call must not be ambiguous
+int i = func<int>(1);