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

Richard Smith richard at metafoo.co.uk
Tue Jan 8 14:20:24 PST 2013


On Tue, Jan 8, 2013 at 2:11 PM, Will Wilson <will at indefiant.com> wrote:
> Righto, thanks for clarifying. Two questions spring to mind:
>
> 1. I assume the same is true for the whole if-else block in
> CheckMemberSpecialization() that applies TSK_ExplicitSpecialization for
> various Decl types?

Yes, those calls to setLocation all look wrong. Do you see any test
failures if you remove them?

> 2. Where should any tests for this change live?

test/SemaCXX/sourceranges.cpp looks like a good candidate.

> On 8 January 2013 22:07, Richard Smith <richard at metafoo.co.uk> wrote:
>>
>> 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
>> :-)
>
>
>
>
> --
> Indefiant Ltd.
>
> Firsby Lodge, New Main Road, Scamblesby, Louth, Lincs LN11 9XH UK
> Tel: +44 20 8123 7663 England Registered No. 07936820 VAT No. 128556202



More information about the cfe-dev mailing list