Skip to content

Commit f3a77c6

Browse files
authored
Merge pull request github#14060 from MathiasVP/fix-compare-where-assign-meant-fp
C++: Fix FP in `cpp/compare-where-assign-meant`
2 parents dbdb433 + 9542646 commit f3a77c6

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

cpp/ql/src/Likely Bugs/Likely Typos/CompareWhereAssignMeant.ql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import cpp
1616
from ExprInVoidContext op
1717
where
1818
not op.isUnevaluated() and
19+
not inMacroExpansion(op) and
1920
(
2021
op instanceof EQExpr
2122
or
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The "Comparison where assignment was intended" query (`cpp/compare-where-assign-meant`) no longer reports comparisons that appear in macro expansions.

cpp/ql/test/query-tests/Likely Bugs/Likely Typos/CompareWhereAssignMeant/CompareWhereAssignMeant.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@
66
| test.cpp:39:23:39:28 | ... == ... | This '==' operator has no effect. The assignment ('=') operator was probably intended. |
77
| test.cpp:42:23:42:28 | ... == ... | This '==' operator has no effect. The assignment ('=') operator was probably intended. |
88
| test.cpp:51:13:51:13 | call to operator== | This '==' operator has no effect. The assignment ('=') operator was probably intended. |
9+
| test.cpp:72:3:72:8 | ... == ... | This '==' operator has no effect. The assignment ('=') operator was probably intended. |
10+
| test.cpp:73:3:73:12 | ... == ... | This '==' operator has no effect. The assignment ('=') operator was probably intended. |

cpp/ql/test/query-tests/Likely Bugs/Likely Typos/CompareWhereAssignMeant/test.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,14 @@ template<typename T1, typename T2>
6161
auto sfinaeTrick(T1 x1, T2 x2) -> decltype(x1 == x2, bool()) { // GOOD
6262
return x1 == x2;
6363
}
64+
65+
void report_error(const char*);
66+
67+
#define DOES_NOT_THROW(E) do { try { E; } catch (...) { report_error(""); } } while(0)
68+
#define ID(X) (X)
69+
70+
void test_inside_macro_expansion(int x, int y) {
71+
DOES_NOT_THROW(x == y); // GOOD
72+
x == y; // BAD
73+
x == ID(y); // BAD
74+
}

0 commit comments

Comments
 (0)