From: Jonathan Wakely Date: Thu, 6 May 2021 12:40:53 +0000 (+0100) Subject: libstdc++: Fix definition of std::remove_cvref_t X-Git-Tag: releases/gcc-11.2.0~419 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=43d3309d98c10f4fde6f12686220fa3e9f4044cf;p=thirdparty%2Fgcc.git 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. (cherry picked from commit 0e79e63026e43ad0577812ffb405dac8fa88af5b) --- diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 1f8b57b04a0d..eaf06fcb036c 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -3223,12 +3223,21 @@ template /// Remove references and cv-qualifiers. template struct remove_cvref - { - using type = __remove_cvref_t<_Tp>; - }; + : remove_cv<_Tp> + { }; + + template + struct remove_cvref<_Tp&> + : remove_cv<_Tp> + { }; + + template + struct remove_cvref<_Tp&&> + : remove_cv<_Tp> + { }; template - using remove_cvref_t = __remove_cvref_t<_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 d4a284229776..a4f50d433dcd 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::type, const int()>::value, ""); } + +// Declare using nested name of class template +template T func(typename std::remove_cvref::type); +// Define using alias +template T func(std::remove_cvref_t t) { return t; } +// Call must not be ambiguous +int i = func(1);