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

Richard Smith richard at metafoo.co.uk
Tue Jan 8 13:07:04 PST 2013


On Tue, Jan 8, 2013 at 6:22 AM, Will Wilson <will at indefiant.com> wrote:
> 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?

This is a bug. We shouldn't be updating the location of the
declaration when we see the explicit specialization. Patches welcome
:-)



More information about the cfe-dev mailing list