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.
This commit is contained in:
Jonathan Wakely 2021-05-06 13:40:53 +01:00
parent 7411554686
commit 0e79e63026
2 changed files with 20 additions and 4 deletions

View File

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

View File

@ -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);