Compiling with Clang 3.0 -std=c++98, the following code is accepted:
template<int>
struct I
{
typedef int Type;
};
template<class>
struct S
{
static int f(int);
//static int f(int*);
// implicitly instantiates I<sizeof(int)>
typedef I<sizeof(f(0))>::Type Type;
};
S<int>::Type s;
Uncommenting the overload of 'f' causes Clang to report an error "missing 'typename' prior to dependent type name". G++ 4.8 reports the same error with or without the overload. msvc10 does not give any errors with or without the overload.
Where does the standard say whether or not 'f' is dependent and 'typename' is required? If 'typename' is not required, where does the standard say whether or not overload resolution should be performed in this scenario?
EDIT:
To clarify: the reason I mention overload resolution is that it may be necessary to perform overload resolution to determine the value of the constant-expression 'sizeof(f(0))'. If (as I assume) overload resolution is not performed when determining whether an expression is type-dependent, the value of the constant-expression 'sizeof(f(0))' is impossible to determine (at parse time) when a dependent overload of 'f' exists: e.g.
template<int>
struct I
{
typedef int Type;
};
template<class T>
struct S
{
static T f(int);
typedef typename I<sizeof(f(0))>::Type Type;
};
S<int>::Type t;
Compiling with Clang 3.0 -std=c++98, this produces no errors. This seems correct to me, because the standard deems an expression to be type-dependent if it is an id-expression naming an object declared with a dependent type.
sizeof
unary-expression"; [temp.dep.constexpr]/2 "Expressions of the following form are value-dependent if the unary-expression is type-dependent or the type-id is dependent [...]sizeof
unary-expression" – dypf(0)
is not a type-dependent nor a value-dependent expression AFAIK – dyptypedef I<sizeof(&f)>::Type Type;
ifff
is a static function (but not if it's a static data member). – dyp