Skip to content

Commit 403899e

Browse files
authored
Merge pull request #2391 from jbj/CompareWhereAssignMeant-decltype
C++: Fix FP for expression SFINAE with decltype
2 parents 77c869f + ff96e3a commit 403899e

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ import cpp
1515

1616
from ExprInVoidContext op
1717
where
18-
op instanceof EQExpr
19-
or
20-
op.(FunctionCall).getTarget().hasName("operator==")
18+
not op.isUnevaluated() and
19+
(
20+
op instanceof EQExpr
21+
or
22+
op.(FunctionCall).getTarget().hasName("operator==")
23+
)
2124
select op, "This '==' operator has no effect. The assignment ('=') operator was probably intended."

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ where
8686
not peivc.isFromTemplateInstantiation(_) and
8787
parent = peivc.getParent() and
8888
not parent.isInMacroExpansion() and
89+
not peivc.isUnevaluated() and
8990
not parent instanceof PureExprInVoidContext and
9091
not peivc.getEnclosingFunction().isCompilerGenerated() and
9192
not peivc.getType() instanceof UnknownType and

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,9 @@ void f(void) {
5555
}
5656
}
5757

58+
// This pattern is used to emulate C++20 concepts in a way that's very light on
59+
// template syntax.
60+
template<typename T1, typename T2>
61+
auto sfinaeTrick(T1 x1, T2 x2) -> decltype(x1 == x2, bool()) { // GOOD
62+
return x1 == x2;
63+
}

0 commit comments

Comments
 (0)