I noticed that gcc 5.0 rejects the following code, while clang 3.6 accepts it.
template<int n>
struct I
{
typedef int Type;
};
template<typename T>
struct A
{
typedef I<sizeof(sizeof(T))>::Type Type;
};
The two compilers seem to differ on whether sizeof(sizeof(T))
is a type-dependent or value-dependent expression. If the expression were dependent, then it follows that I<sizeof(sizeof(T))>
is a dependent type, meaning that typename
should be required.
This is covered by the following wording in the C++11 standard:
[temp.dep.type]/8
A type is dependent if it is
- a simple-template-id in which either the template name is a template parameter or any of the template arguments is a dependent type or an expression that is type-dependent or value-dependent
[temp.dep.expr]/4
Expressions of the following forms are never type-dependent (because the type of the expression cannot be dependent):
sizeof unary-expression sizeof ( type-id )
[temp.dep.constexpr]/2
Expressions of the following form are value-dependent if the unary-expression or expression is typedependent or the type-id is dependent:
sizeof unary-expression sizeof ( type-id )
My interpretation is that sizeof(T)
can never be type-dependent, meaning sizeof(sizeof(T))
can never be type-dependent or value-dependent.
Is this a bug in gcc?