[cfe-dev] Source location for the template keyword.
John McCall
rjmccall at apple.com
Mon Sep 13 11:20:30 PDT 2010
On Sep 13, 2010, at 10:29 AM, Enea Zaffanella wrote:
> template <typename T>
> struct S {
> template <class U> static int foo(U*);
>
> static const unsigned s = sizeof(S<T>::template foo<T>(0));
> };
>
> The argument of sizeof is an UnresolvedLookupExpr.
Assuming you mean the operand of the CallExpr inside the sizeof, yes.
Note that the 'template' is actually unnecessary here because the NNS
refers to the current instantiation.
> We were considering the addition of a SourceLocation for the template
> keyword to UnresolvedLookupExpr and similar AST nodes. Such a source
> location will be invalid if the keyword is not written in the sources.
> Afawct, there are examples when such a template keyword is needed (as
> the one above) and other examples where it is just optional; a possibly
> invalid source location should be enough to distinguish among all
> possibilities.
>
> Afawct, the template keyword can appear (it is meant, after the nested
> name specifier and before the declaration name) in the following
> expressions:
>
> DeclRefExpr
> MemberExpr
> DependentScopeDeclRefExpr
> CXXDependentScopeMemberExpr
> UnresolvedLookupExpr
> UnresolvedMemberExpr
>
> What about CXXUnresolvedConstructExpr?
Yes, but only in the NNS case; see below.
> Are there other cases?
It can also happen within an arbitrary nested name specifier:
A<T>::template B<T>::foo
If we were able to say "this NNS ends with a 'template' keyword", that would
be sufficient for all these cases except the member expressions
(where it's possible to have 'a.template foo<>()').
John.
More information about the cfe-dev
mailing list