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

Will Wilson will at indefiant.com
Tue Jan 8 14:11:21 PST 2013


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?

2. Where should any tests for this change live?


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*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130108/c2b10da5/attachment.html>


More information about the cfe-dev mailing list