[cfe-dev] Incorrect source range for specialized template VarDecl declaration

Will Wilson will at indefiant.com
Tue Jan 8 06:22:14 PST 2013


Hi All,

I've run into what looks like a bug (or possibly ambiguous behaviour) when
examining specialized static members of a templated class.

template <typename T>
class TemplatedClass
{
public:
static int Foo;
};

template <typename T>
int TemplatedClass<T>::Foo = 1;

template <>
int TemplatedClass<int>::Foo = 2;

The <int> specialization generates two VarDecls (as expected), one for the
declaration and one for the definition. However if you query
getSourceRange() for the declaration it will give you a range extending
from the declaration to the definition - rather than one simply covering
the declaration. This proves problematic when it comes to rewriting such
declarations.

The declaration's location is set to the definition location
by Sema::CheckMemberSpecialization(). In some ways this is correct as
the specialization obviously "spawns" the specialized declaration but it
does make the SourceRange somewhat useless in this case.

Any thoughts on this? It's easily resolved by removing the setLocation()
call in CheckMemberSpecialization() but my feeling is this may be incorrect
(or at least losing information). It's almost like there should be a
"SourceLocation PointOfSpecialization" member in MemberSpecializationInfo -
but perhaps I'm completely on the wrong track?

Obviously, I guess I can fall back on querying the non-specialized
declaration for the SourceRange but this feels more than a little ugly.

- Will.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130108/f09ff911/attachment.html>


More information about the cfe-dev mailing list