Skip to content

Commit 067d4a4

Browse files
committed
C++: Exclude more comparisons from cpp/constant-comparison
1 parent 5bbabe8 commit 067d4a4

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

cpp/ql/src/Likely Bugs/Arithmetic/PointlessComparison.ql

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,21 @@ import UnsignedGEZero
2525
//
2626
// So to reduce the number of false positives, we do not report a result if
2727
// the comparison is in a macro expansion. Similarly for template
28-
// instantiations.
28+
// instantiations. We also exclude comparisons in static asserts, as these
29+
// should be pointless.
2930
from ComparisonOperation cmp, SmallSide ss, float left, float right, boolean value, string reason
3031
where
3132
not cmp.isInMacroExpansion() and
3233
not cmp.isFromTemplateInstantiation(_) and
34+
not exists(StaticAssert s | s.getCondition() = cmp.getParent*()) and
35+
not exists(Declaration d | d.getATemplateArgument() = cmp.getParent*()) and
36+
not exists(Variable v |
37+
v.isConstexpr()
38+
or
39+
v.isConst() and v.isStatic()
40+
|
41+
v.getInitializer().getExpr() = cmp.getParent*()
42+
) and
3343
not functionContainsDisabledCode(cmp.getEnclosingFunction()) and
3444
reachablePointlessComparison(cmp, left, right, value, ss) and
3545
// a comparison between an enum and zero is always valid because whether

0 commit comments

Comments
 (0)