I've been playing with trailing return types that resolve to the same type, with a different expression, but resolves to something legal. This works:
template <typename>
struct Cls {
static std::size_t f();
};
template <typename T>
auto Cls<T>::f() -> decltype(std::size_t{}) { return 0; }
But if I change the definition to something that should be equivalent, it fails
template <typename T>
auto Cls<T>::f() -> decltype(sizeof(T)) { return 0; }
clang's error (gcc is similar):
error: return type of out-of-line definition of 'Cls::f' differs from that in the declaration
auto Cls<T>::f() -> decltype(sizeof(T)) { return 0; }
^
note: previous declaration is here
static std::size_t f();
~~~~~~~~~~~ ^
If I replace sizeof(T)
with sizeof(int)
it compiles successfully. Why is it illegal with a dependent type only?
Aucun commentaire:
Enregistrer un commentaire