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

Nico Weber thakis at chromium.org
Wed Nov 17 15:22:04 PST 2010


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.

My patch adds an end location to TypeSpecTypeLoc and fills it in in
TypeSpecLocFiller::VisitTagTypeLoc(). The rest of the patch consists
of copying this new TypeSpecTypeLoc field every time a TypeSpecTypeLoc
is copied, which happens in surprisingly many places.

Acurate sourceranges on all ast nodes are important for writing rewriters.

Nico
-------------- next part --------------
A non-text attachment was scrubbed...
Name: newrange.patch
Type: application/octet-stream
Size: 10841 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20101118/f3d23e4d/attachment.obj>


More information about the cfe-dev mailing list