Skip to content

Commit 96c73bc

Browse files
committed
C++: Fix FP: bad Location for FieldAccess exprs
1 parent 6d5df14 commit 96c73bc

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@ Expr normalizeExpr(Expr e) {
1616
if exists(e.(Call).getQualifier())
1717
then result = normalizeExpr(e.(Call).getQualifier())
1818
else
19-
if e.hasExplicitConversion()
20-
then result = normalizeExpr(e.getFullyConverted())
21-
else result = e
19+
if exists(e.(FieldAccess).getQualifier())
20+
then result = normalizeExpr(e.(FieldAccess).getQualifier())
21+
else
22+
if e.hasExplicitConversion()
23+
then result = normalizeExpr(e.getFullyConverted())
24+
else result = e
2225
}
2326

2427
predicate isInLoopHead(CommaExpr ce) {
@@ -45,4 +48,4 @@ where
4548
not isInDecltypeOrSizeof(ce) and // <- Removes arguable FPs since, like function calls (and loop heads), these Exprs have clear delimiters.
4649
leftLoc.getEndLine() < rightLoc.getStartLine() and
4750
leftLoc.getStartColumn() > rightLoc.getStartColumn()
48-
select right, "The indentation after the comma may be misleading (for some tab sizes)."
51+
select right, "The indentation level may be misleading (for some tab sizes)."

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,26 @@ int test(int i, int j, int (*foo)(int), int (*bar)(int, int))
122122
i++
123123
), j++); // GOOD?
124124

125-
// Weird case:
125+
// Weird cases:
126126

127127
if (foo(j))
128128
return i++
129129
, i++ // GOOD(?) [FALSE POSITIVE] -- can't exclude w/o source code text :/
130130
? 1
131131
: 2;
132132

133-
return 0;
133+
struct {
134+
struct {
135+
void tutu() {}
136+
long toto() { return 42; }
137+
} titi;
138+
} *tata;
139+
140+
int quux =
141+
(tata->titi.tutu(),
142+
foo(tata->titi.toto())); // GOOD
143+
144+
return quux;
134145
}
135146

136147
// Comma in variadic template splice:

0 commit comments

Comments
 (0)