C++: Exclude commas in if-conditions.

This commit is contained in:
Nora Dimitrijević
2022-09-29 16:29:57 +02:00
parent 64903336f7
commit 29d7c0e21b
2 changed files with 8 additions and 0 deletions

View File

@@ -42,6 +42,8 @@ predicate isParenthesized(CommaExpr ce) {
isInDecltypeOrSizeof(ce)
or
ce.getParent*().(Expr).isParenthesised()
or
ce.getParent*() = any(IfStmt i).getCondition()
}
from CommaExpr ce, Expr left, Expr right, Location leftLoc, Location rightLoc

View File

@@ -137,6 +137,12 @@ int Foo::test(int (*baz)(int))
j = 1; i < 10; i += 2, // GOOD? Currently ignoring loop heads.
j++) {}
// Comma in if-conditions:
if (i = foo(j++),
i == j) // GOOD(?) -- Currently ignoring if-conditions for the same reason as other parenthesized commas.
i = 0;
// Mixed tabs and spaces (ugly case):
for (i = 0, // GOOD if tab >= 4 spaces else BAD -- Currently ignoring loop heads.