I have the following implementation of CommonType which is similar to std::common_type (without decay) along with static_assert's to test the behavior:
template <typename... T>
struct CommonType;
template <typename T>
struct CommonType<T>
{
typedef T type;
};
template <typename T, typename U>
struct CommonType<T, U>
{
typedef decltype(true ? std::declval<T>() : std::declval<U>()) type;
};
template <typename T, typename U, typename... TRest>
struct CommonType<T, U, TRest...>
{
typedef typename CommonType<typename CommonType<T, U>::type, TRest...>::type type;
};
// On Clang 3.5.0 CommonType returns int&&
// On GCC 4.6.3 CommonType returns int
static_assert(std::is_same<int&&, CommonType<int, int>::type>::value, "Clang
success on assert , GCC fails");
static_assert(std::is_same<int, CommonType<int, int>::type>::value, "Clang
fails assert, GCC Success");
The static_asserts
indicate a difference between GCC and Clang.
This post indicates that declval<A>
should return A&&
.
Does that mean that GCC has a defect here with declval<A>
?
Aucun commentaire:
Enregistrer un commentaire