<div dir="ltr"><div class="gmail_quote"><div>Unfortunately clang doesn't have the location of the semicolon in statements, mostly because Statements are the base class of Expressions (for historical reasons that do not apply any more).</div><div><br></div><div>Thus, fixits that want to get to the semicolon need to use the Lexer to get at it. Looping in clang-tidy folks for whether we have infrastructure in clang-tidy for that already...</div><div dir="ltr"><br></div><div dir="ltr">On Tue, Feb 2, 2016 at 7:31 PM Tim Halloran via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hopefully a simple question. I'm removing a using namespace directive from the code in a simple check. so<div><br></div><div>using namespace std;</div><div><br></div><div>gets removed from a C++ file my code however ends up with</div><div><br></div><div>;</div><div><br></div><div>when I run</div><div><br></div><div><div>clang-tidy -checks=-*,surelogic* -fix-errors test1.cpp -- -std=c++14</div><div>4 warnings generated.</div><div>/home/tim/Source/llvm-work/test1.cpp:8:1: warning: do not use namespace using-directives; use using-declarations instead [surelogic-readability-using]</div><div>using namespace std;</div><div>^</div><div>/home/tim/Source/llvm-work/test1.cpp:8:1: note: FIX-IT applied suggested code changes</div><div>using namespace std;</div><div>^</div><div><<snip>></div><div>clang-tidy applied 2 of 2 suggested fixes.<br></div><div><br></div><div>The non-boilerplate code is below:</div><div><br></div><div><div> void UsingCheck::registerMatchers(ast_matchers::MatchFinder *Finder) {</div><div> // Only register the matchers for C++; the functionality currently does not</div><div> // provide any benefit to other languages, despite being benign.</div><div> if (getLangOpts().CPlusPlus)</div><div> Finder->addMatcher(usingDirectiveDecl().bind("usingNamespace"), this);</div><div> }</div><div> </div><div> void</div><div>UsingCheck::check(const MatchFinder::MatchResult &Result) {</div><div> const auto *U = Result.Nodes.getNodeAs<UsingDirectiveDecl>("usingNamespace");</div><div> SourceLocation Loc = U->getLocStart();</div><div> if (U->isImplicit() || !Loc.isValid())</div><div> return;</div><div> </div><div> diag(Loc, "do not use namespace using-directives; "</div><div> "use using-declarations instead") << FixItHint::CreateRemoval(U->getSourceRange());</div><div> }</div></div><div><br></div><div><div>(yes this is clone of the google check, just to learn)</div><div><br></div><div>But I'm wondering what to do to get the semicolon. I don't see it in the AST dump output...below</div><div><br></div><div><<snip stuff in my test code>></div><div><div>|-FunctionDecl 0x482c160 <mod.cpp:5:1, col:37> col:5 used foo 'int (class Point)'</div><div>| |-ParmVarDecl 0x482c098 <col:9, col:15> col:15 used p 'class Point'</div><div>| `-CompoundStmt 0x482c2b0 <col:18, col:37></div><div>| `-ReturnStmt 0x482c298 <col:20, col:34></div><div>| `-CXXMemberCallExpr 0x482c270 <col:27, col:34> 'int'</div><div>| `-MemberExpr 0x482c238 <col:27, col:29> '<bound member function type>' .getX 0x482b178</div><div>| `-DeclRefExpr 0x482c210 <col:27> 'class Point' lvalue ParmVar 0x482c098 'p' 'class Point'</div><div><< The using directive is next >></div><div>|-UsingDirectiveDecl 0x482c2d0 <line:8:1, col:17> col:17 Namespace 0x409b938 'std'</div><div><< next a function decl in my test code>></div><div>`-FunctionDecl 0x482c340 <line:10:1, line:41:1> line:10:5 main 'int (void)'</div><div> `-CompoundStmt 0x486d200 <col:12, line:41:1></div></div><div><br></div><div>Any suggestions?</div>-- <br><div>Tim Halloran<br>SureLogic, Inc.<br>5808 Forbes Avenue, Pittsburgh PA 15217-1602<br>(412) 722-3338</div>
</div></div></div>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div></div>