[cfe-dev] End location of DeclStmt

Jonas Toth via cfe-dev cfe-dev at lists.llvm.org
Sun Dec 2 04:09:09 PST 2018


Hi Pardis,

which location does the `getEnd()` return?
I assume it's one byte to early: You can do offset-calculations with
`SourceLocation`, therefore `YourStmt->getEnd().getLocWithOffset(1)`
returns one element past the end-location.
Be careful with corner-cases as the new Location might be invalid, in a
Macro-Range (isMarcoID()) and so on. Please note, that the `DeclStmt`
might not always have a semicolon after itself.
E.g. `int my_variable = 42 /* This is my variable */;` could be such a
case. You might want to take a look 
`clang-tidy/utils/LexerUtils.{h,cpp}` as it has some functionality to
deal with such situations.

Best, Jonas


Am 02.12.18 um 02:50 schrieb Pardis Pashakhanloo via cfe-dev:
> Hi all,
>
> My goal is to remove a DeclStmt from the beginning to end (including
> the semicolon) using the Rewriter.
> However, calling getEnd() on a DeclStmt does not give the correct
> location. Is there a way to get the end location properly?
>
> Best,
> Pardis
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20181202/3b1d25a9/attachment.html>


More information about the cfe-dev mailing list