Skip to content

Commit 29d7c0e

Browse files
committed
C++: Exclude commas in if-conditions.
1 parent 6490333 commit 29d7c0e

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

cpp/ql/src/Best Practices/Likely Errors/CommaBeforeMisleadingIndentation.ql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ predicate isParenthesized(CommaExpr ce) {
4242
isInDecltypeOrSizeof(ce)
4343
or
4444
ce.getParent*().(Expr).isParenthesised()
45+
or
46+
ce.getParent*() = any(IfStmt i).getCondition()
4547
}
4648

4749
from CommaExpr ce, Expr left, Expr right, Location leftLoc, Location rightLoc

cpp/ql/test/query-tests/Best Practices/Likely Errors/CommaBeforeMisleadingIndentation/test.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ int Foo::test(int (*baz)(int))
137137
j = 1; i < 10; i += 2, // GOOD? Currently ignoring loop heads.
138138
j++) {}
139139

140+
// Comma in if-conditions:
141+
142+
if (i = foo(j++),
143+
i == j) // GOOD(?) -- Currently ignoring if-conditions for the same reason as other parenthesized commas.
144+
i = 0;
145+
140146
// Mixed tabs and spaces (ugly case):
141147

142148
for (i = 0, // GOOD if tab >= 4 spaces else BAD -- Currently ignoring loop heads.

0 commit comments

Comments
 (0)