Both clang 3.6 and gcc 5.0 require typename
in the following example:
template<typename T>
struct B
{
typedef int Type;
};
void f(int);
template<int n>
struct A
{
typedef typename B<decltype(f(n))>::Type Type;
};
This is covered by the following wording in the C++11 standard:
[temp.dep.type]/5
A name is a member of an unknown specialization if it is
- A qualified-id in which the nested-name-specifier names a dependent type that is not the current instantiation.
[temp.dep.type]/8
A type is dependent if it is
a member of an unknown specialization,
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
denoted by
decltype(expression)
, where expression is type-dependent
This suggests B<decltype(f(n))>::Type
is type-dependent only if B<decltype(f(n))>
is type-dependent. Also that B<decltype(f(n))>
is dependent only if f(n)
is type-dependent.
[temp.dep.expr]/1
Except as described below, an expression is type-dependent if any subexpression is type-dependent.
[temp.dep.expr]/3
An id-expression is type-dependent if it contains
an identifier associated by name lookup with one or more declarations declared with a dependent type,
a template-id that is dependent,
a conversion-function-id that specifies a dependent type, or
a nested-name-specifier or a qualified-id that names a member of an unknown specialization;
or if it names a static data member of the current instantiation that has type “array of unknown bound of T” for some T
This suggests f(n)
is type-dependent only if n
is type-dependent, and that n
is not type-dependent.
Am I missing something, or is this a compiler bug?
f(n)
with*new int(n)
which is not type-dependent according to [temp.dep.expr]/3 – willj