[cfe-dev] Stmt::getLocEnd() behaviour

Eli Friedman eli.friedman at gmail.com
Wed Mar 28 13:17:32 PDT 2012


On Wed, Mar 28, 2012 at 1:00 PM, Robert Ankeney <rrankene at gmail.com> wrote:
> I've been playing with Clang to see what it can do, and thinking of
> writing a Rewriter tutorial.  I was thinking of rewriting statements
> of the form:
>   if (expr)
>     stmt;
> to:
>   if (expr)
>   {
>      stmt;
>   }
> as a way to enforce some coding standards I've seen.  I coupled a
> RecursiveASTVisitor with a rewriter, and when visiting an IfStmt, I
> expected getLocEnd() to point at the end of the if statement.  What I
> get instead is somewhere inside the stmt.  Is that expected behaviour?

Arguably a bug... it's a side-effect of getLocEnd on if statements
forwarding to the contained statement, which is an expression in this
case. That said, getting from one SourceLocation to the other isn't
too hard with MeasureTokenLength.

-Eli




More information about the cfe-dev mailing list