<div dir="ltr">Hello, <div>I want to emit some text after each if statement in source code. When testing a tool I've found that ifStmt->getSourceRange() sometimes returns wrong end location. </div><div><br></div><div>In RecursiveASTVisitor I have following code to insert "$" before and after each if:</div><div><font face="monospace, monospace"><br></font></div><div><div><font face="monospace, monospace">    bool VisitIfStmt(clang::IfStmt* ifStmt)</font></div><div><font face="monospace, monospace">    {</font></div><div><font face="monospace, monospace">        clang::tooling::Replacement rep0(compInst.getSourceManager(), ifStmt->getLocStart(), 0, "$");</font></div><div><font face="monospace, monospace">        handleAllErrors ( replacements.add(rep0) );</font></div><div><font face="monospace, monospace">        clang::tooling::Replacement rep1(compInst.getSourceManager(), ifStmt->getLocEnd().getLocWithOffset(1), 0, "$");</font></div><div><font face="monospace, monospace">        handleAllErrors ( replacements.add(rep1) );</font></div><div><font face="monospace, monospace">        return true;</font></div><div><font face="monospace, monospace">    }</font></div></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace"><div>    Replacements &replacements;</div><div>    ASTContext *Context;</div><div>    clang::CompilerInstance &compInst;</div><div><br></div></font></div><div><div>When testing on following code:</div></div><div><br></div><div><font face="monospace, monospace">    int a;</font></div><div><font face="monospace, monospace">    if (a)<br></font></div><div><div><font face="monospace, monospace">       a--;</font></div></div><div><br></div><div><div>Result is:</div></div><div><font face="monospace, monospace"><br></font></div><div><div><font face="monospace, monospace">    $if (a)</font></div><div><font face="monospace, monospace">       a-$-;</font></div></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace"><br></font></div><div><div>So Clang thinks that if statement ends inside decrement operator. Is it a bug, or I misuse API?</div></div><div><br></div><div>Thanks,</div><div>-Roman</div></div>