Merge pull request #2391 from jbj/CompareWhereAssignMeant-decltype

C++: Fix FP for expression SFINAE with decltype
This commit is contained in:
Geoffrey White
2019-11-20 17:34:09 +00:00
committed by GitHub
3 changed files with 13 additions and 3 deletions

View File

@@ -15,7 +15,10 @@ import cpp
from ExprInVoidContext op from ExprInVoidContext op
where where
op instanceof EQExpr not op.isUnevaluated() and
or (
op.(FunctionCall).getTarget().hasName("operator==") op instanceof EQExpr
or
op.(FunctionCall).getTarget().hasName("operator==")
)
select op, "This '==' operator has no effect. The assignment ('=') operator was probably intended." select op, "This '==' operator has no effect. The assignment ('=') operator was probably intended."

View File

@@ -86,6 +86,7 @@ where
not peivc.isFromTemplateInstantiation(_) and not peivc.isFromTemplateInstantiation(_) and
parent = peivc.getParent() and parent = peivc.getParent() and
not parent.isInMacroExpansion() and not parent.isInMacroExpansion() and
not peivc.isUnevaluated() and
not parent instanceof PureExprInVoidContext and not parent instanceof PureExprInVoidContext and
not peivc.getEnclosingFunction().isCompilerGenerated() and not peivc.getEnclosingFunction().isCompilerGenerated() and
not peivc.getType() instanceof UnknownType and not peivc.getType() instanceof UnknownType and

View File

@@ -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<typename T1, typename T2>
auto sfinaeTrick(T1 x1, T2 x2) -> decltype(x1 == x2, bool()) { // GOOD
return x1 == x2;
}