[PATCH] Enhance clang-tidy readability-simplify-boolean-expr to handle 'if (e) return true; return false; '
legalize at xmission.com
Sun May 24 13:40:13 PDT 2015
After sorting out some things with the clang tree for testing, I discovered that the code had errors. This diff corrects them.
Specifically `compoundStmt(hasAnySubstatement(ifStmt()))` will always match the first `if` statement in a compound statement. The matcher will not be invoked for each `if` statement in the block. So when a block contains chained `if` statements like:
if (i < 5) return false;
if (i > 10) return true;
The first `if` statement would have been matched, but then determined that it did not immediately precede the `return` statement and the entire block would be left alone. The consequence is that I can use a matcher that finds all compound statements containing both an `if` statement and a `return` statement, but I then have to iterate over the compound statement manually to locate the `if` immediately preceding the `return`. Test cases have been added to cover this situation. Running the check on clang/LLVM code now does the sensible thing.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 11938 bytes
Desc: not available
More information about the cfe-commits