Skip to content

Commit 55f33b7

Browse files
committed
C++: Exclude static asserts from cpp/constant-comparison
1 parent 70d5384 commit 55f33b7

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ 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
3335
not functionContainsDisabledCode(cmp.getEnclosingFunction()) and
3436
reachablePointlessComparison(cmp, left, right, value, ss) and
3537
// a comparison between an enum and zero is always valid because whether

0 commit comments

Comments
 (0)