[cfe-dev] [patch] Fix source range of CXXNewExprs

John McCall rjmccall at apple.com
Wed Nov 17 15:36:49 PST 2010


On Nov 17, 2010, at 3:35 PM, Nico Weber wrote:

> On Thu, Nov 18, 2010 at 12:29 AM, John McCall <rjmccall at apple.com> wrote:
>> 
>> On Nov 17, 2010, at 3:22 PM, Nico Weber wrote:
>> 
>>> Hi,
>>> 
>>> the attached patch fixes the source range on CXXNewExprs. For code like
>>> 
>>>  foo:A* a = new foo::A;
>>> 
>>> the CXXNewExpr's source range's end would point to `foo` instead of
>>> `A`. This was because Sema::BuildCXXNew() uses the allocated type's
>>> TypeLoc's source range's end as end location for CXXNewExpr if no
>>> parens are present (new foo::A() is handled correctly already), and
>>> TypeSpecTypeLoc has only a start location.
>> 
>> This should be an ElaboratedTypeLoc.  If it isn't, that's the bug, not changing
>> TypeSpecTypeLoc.
> 
> It is an ElaboratedTypeLoc, but TypeLoc::getEndLoc() skips the
> ElaboratedTypeLoc's position and moves on the next loc:

Ah.  So the problem is that the TypeSpecTypeLoc's location should be
the location of the qualified identifier, not the location of the start of the
qualification.

John.



More information about the cfe-dev mailing list