Help reg. clang

Hi,

I am trying to produce warnings when semicolon is found after if,for,while loops.How to achieve this solution using ast matcher?.Basically, have to match null statement inside a loop(for,if,while).Any help is appreciated.

Swaresh
IIT Bombay,India

There is already some handling for this type of thing. Perhaps this does not suffice for your purposes but it is likely worth a look.

See warnings in Sema::ActOnIfStmt (that calls Sema::DiagnoseEmptyStmtBody) and Sema::DiagnoseEmptyLoopBody (in lib/Sema/SemaChecking.cpp and lib/Sema/SemaStmt.cpp respectively).

Nemanja

There's also a pretty ambitious clang-tidy check for exactly this:
http://clang.llvm.org/extra/clang-tidy/checks/misc-suspicious-semicolon.html

It was added quite recently:
http://reviews.llvm.org/D16535

- Kim

As with most warnings, there are respective -W options to enable them. For example, -Wempty-body. That should be on by default though. Keep in mind that there are conditions under which you get no warnings (you can see it in the code). For example, you WILL NOT get the empty body warning for a loop with an empty body if the semicolon follows the loop header and the next statement is NOT indented.

And of course, you can look at the clang-tidy checks as Kim mentioned.