diff --git a/cpp/ql/src/Likely Bugs/Likely Typos/CompareWhereAssignMeant.ql b/cpp/ql/src/Likely Bugs/Likely Typos/CompareWhereAssignMeant.ql index eb60eebeeb8..402f26d875e 100644 --- a/cpp/ql/src/Likely Bugs/Likely Typos/CompareWhereAssignMeant.ql +++ b/cpp/ql/src/Likely Bugs/Likely Typos/CompareWhereAssignMeant.ql @@ -15,7 +15,10 @@ import cpp from ExprInVoidContext op where - op instanceof EQExpr - or - op.(FunctionCall).getTarget().hasName("operator==") + not op.isUnevaluated() and + ( + op instanceof EQExpr + or + op.(FunctionCall).getTarget().hasName("operator==") + ) select op, "This '==' operator has no effect. The assignment ('=') operator was probably intended." diff --git a/cpp/ql/src/Likely Bugs/Likely Typos/ExprHasNoEffect.ql b/cpp/ql/src/Likely Bugs/Likely Typos/ExprHasNoEffect.ql index 96279c398fd..e51e5c6764f 100644 --- a/cpp/ql/src/Likely Bugs/Likely Typos/ExprHasNoEffect.ql +++ b/cpp/ql/src/Likely Bugs/Likely Typos/ExprHasNoEffect.ql @@ -86,6 +86,7 @@ where not peivc.isFromTemplateInstantiation(_) and parent = peivc.getParent() and not parent.isInMacroExpansion() and + not peivc.isUnevaluated() and not parent instanceof PureExprInVoidContext and not peivc.getEnclosingFunction().isCompilerGenerated() and not peivc.getType() instanceof UnknownType and 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 91d8d026006..d3adcb50421 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 @@ -55,3 +55,9 @@ void f(void) { } } +// This pattern is used to emulate C++20 concepts in a way that's very light on +// template syntax. +template +auto sfinaeTrick(T1 x1, T2 x2) -> decltype(x1 == x2, bool()) { // GOOD + return x1 == x2; +}