diff --git a/cpp/ql/src/Likely Bugs/Likely Typos/CompareWhereAssignMeant.ql b/cpp/ql/src/Likely Bugs/Likely Typos/CompareWhereAssignMeant.ql index 402f26d875e..46c271b11d7 100644 --- a/cpp/ql/src/Likely Bugs/Likely Typos/CompareWhereAssignMeant.ql +++ b/cpp/ql/src/Likely Bugs/Likely Typos/CompareWhereAssignMeant.ql @@ -16,6 +16,7 @@ import cpp from ExprInVoidContext op where not op.isUnevaluated() and + not inMacroExpansion(op) and ( op instanceof EQExpr or diff --git a/cpp/ql/src/change-notes/2023-08-25-compare-where-assign-meant.md b/cpp/ql/src/change-notes/2023-08-25-compare-where-assign-meant.md new file mode 100644 index 00000000000..8872ba413fb --- /dev/null +++ b/cpp/ql/src/change-notes/2023-08-25-compare-where-assign-meant.md @@ -0,0 +1,4 @@ +--- +category: minorAnalysis +--- +* The "Comparison where assignment was intended" query (`cpp/compare-where-assign-meant`) no longer reports comparisons that appear in macro expansions. diff --git a/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/CompareWhereAssignMeant/CompareWhereAssignMeant.expected b/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/CompareWhereAssignMeant/CompareWhereAssignMeant.expected index 1beb220e5a1..75ecd8f2452 100644 --- a/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/CompareWhereAssignMeant/CompareWhereAssignMeant.expected +++ b/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/CompareWhereAssignMeant/CompareWhereAssignMeant.expected @@ -6,3 +6,5 @@ | test.cpp:39:23:39:28 | ... == ... | This '==' operator has no effect. The assignment ('=') operator was probably intended. | | test.cpp:42:23:42:28 | ... == ... | This '==' operator has no effect. The assignment ('=') operator was probably intended. | | test.cpp:51:13:51:13 | call to operator== | This '==' operator has no effect. The assignment ('=') operator was probably intended. | +| test.cpp:72:3:72:8 | ... == ... | This '==' operator has no effect. The assignment ('=') operator was probably intended. | +| test.cpp:73:3:73:12 | ... == ... | This '==' operator has no effect. The assignment ('=') operator was probably intended. | diff --git a/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/CompareWhereAssignMeant/test.cpp b/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/CompareWhereAssignMeant/test.cpp index d3adcb50421..2fa42105905 100644 --- a/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/CompareWhereAssignMeant/test.cpp +++ b/cpp/ql/test/query-tests/Likely Bugs/Likely Typos/CompareWhereAssignMeant/test.cpp @@ -61,3 +61,14 @@ template auto sfinaeTrick(T1 x1, T2 x2) -> decltype(x1 == x2, bool()) { // GOOD return x1 == x2; } + +void report_error(const char*); + +#define DOES_NOT_THROW(E) do { try { E; } catch (...) { report_error(""); } } while(0) +#define ID(X) (X) + +void test_inside_macro_expansion(int x, int y) { + DOES_NOT_THROW(x == y); // GOOD + x == y; // BAD + x == ID(y); // BAD +}