[cfe-dev] Source location for the template keyword.
Enea Zaffanella
zaffanella at cs.unipr.it
Mon Sep 13 10:29:04 PDT 2010
Hello.
It seems that the AST representation is missing information regarding
the presence and the source location of the 'template' keyword in a few
expression nodes.
For instance, consider the following example:
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.
This gets pretty printed as follows:
template <typename T> struct S {
template <class U> static int foo(U *);
static const unsigned int s = sizeof (S<T>::foo<T>(0));
};
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?
Are there other cases?
For the DeclRefExpr and MemberExpr nodes, we could add it to the
ExplicitTemplateArgs structure (even though, strictly speaking, the
template keyword is not part of the template args ... this way it will
go after the end of the node, taking no space if there are no explicit
template arguments).
For the Unresolved* nodes, we guess that it should be stored in the
common base class OverloadedExpr.
Does this proposal sound OK?
Regards,
Enea.
More information about the cfe-dev
mailing list