diff --git a/cpp/ql/src/Likely Bugs/Arithmetic/PointlessComparison.ql b/cpp/ql/src/Likely Bugs/Arithmetic/PointlessComparison.ql index e2fe02be867..df6648b5ff4 100644 --- a/cpp/ql/src/Likely Bugs/Arithmetic/PointlessComparison.ql +++ b/cpp/ql/src/Likely Bugs/Arithmetic/PointlessComparison.ql @@ -25,11 +25,14 @@ import UnsignedGEZero // // So to reduce the number of false positives, we do not report a result if // the comparison is in a macro expansion. Similarly for template -// instantiations. +// instantiations, static asserts, non-type template arguments, and constexprs. from ComparisonOperation cmp, SmallSide ss, float left, float right, boolean value, string reason where not cmp.isInMacroExpansion() and not cmp.isFromTemplateInstantiation(_) and + not exists(StaticAssert s | s.getCondition() = cmp.getParent*()) and + not exists(Declaration d | d.getATemplateArgument() = cmp.getParent*()) and + not exists(Variable v | v.isConstexpr() | v.getInitializer().getExpr() = cmp.getParent*()) and not functionContainsDisabledCode(cmp.getEnclosingFunction()) and reachablePointlessComparison(cmp, left, right, value, ss) and // a comparison between an enum and zero is always valid because whether diff --git a/cpp/ql/test/query-tests/Likely Bugs/Arithmetic/PointlessComparison/PointlessComparison.expected b/cpp/ql/test/query-tests/Likely Bugs/Arithmetic/PointlessComparison/PointlessComparison.expected index 4758d2ad04a..6c273b985ee 100644 --- a/cpp/ql/test/query-tests/Likely Bugs/Arithmetic/PointlessComparison/PointlessComparison.expected +++ b/cpp/ql/test/query-tests/Likely Bugs/Arithmetic/PointlessComparison/PointlessComparison.expected @@ -50,9 +50,4 @@ | PointlessComparison.cpp:43:6:43:29 | ... >= ... | Comparison is always true because ... >> ... >= 140737488355327.5. | | PointlessComparison.cpp:44:6:44:28 | ... >= ... | Comparison is always true because ... >> ... >= 140737488355327.5. | | RegressionTests.cpp:57:7:57:22 | ... <= ... | Comparison is always true because * ... <= 4294967295. | -| RegressionTests.cpp:131:17:131:25 | ... < ... | Comparison is always true because 43 <= ... + .... | -| RegressionTests.cpp:135:26:135:52 | ... < ... | Comparison is always false because 16 >= ... * .... | -| RegressionTests.cpp:140:50:140:61 | ... < ... | Comparison is always false because ... * ... >= 84. | -| RegressionTests.cpp:154:21:154:31 | ... < ... | Comparison is always false because ... - ... >= 34. | -| RegressionTests.cpp:154:21:154:31 | ... < ... | Comparison is always false because ... - ... >= 38. | | Templates.cpp:9:10:9:24 | ... <= ... | Comparison is always true because local <= 32767. | diff --git a/cpp/ql/test/query-tests/Likely Bugs/Arithmetic/PointlessComparison/RegressionTests.cpp b/cpp/ql/test/query-tests/Likely Bugs/Arithmetic/PointlessComparison/RegressionTests.cpp index 17972a2536f..84936325e82 100644 --- a/cpp/ql/test/query-tests/Likely Bugs/Arithmetic/PointlessComparison/RegressionTests.cpp +++ b/cpp/ql/test/query-tests/Likely Bugs/Arithmetic/PointlessComparison/RegressionTests.cpp @@ -128,17 +128,17 @@ void testTempObject() { void staticAssert() { static const int a = 42; static const int b = 43; - static_assert(a < b + 0, ""); // GOOD [FALSE POSITIVE] + static_assert(a < b + 0, ""); // GOOD } constexpr int global_1 = 42; -constexpr int global_2 = global_1 < 2 * sizeof(int*) ? 43 : 2 * sizeof(int*); // GOOD [FALSE POSITIVE] +constexpr int global_2 = global_1 < 2 * sizeof(int*) ? 43 : 2 * sizeof(int*); // GOOD static const int global_3 = 42; static const int global_4 = global_3 < 2 * sizeof(int*) ? 43 : 2 * sizeof(int*); // GOOD template -struct templateCompare : public templateCompare // GOOD [FALSE POSITIVE] +struct templateCompare : public templateCompare // GOOD { }; template< unsigned int p, unsigned int n> @@ -151,7 +151,7 @@ unsigned int templateCompare_x = templateCompare<42, 42>::v; template struct someType { - typedef someType<((n - 4) < 0 ? 0 : n - 4)> b; // GOOD [FALSE POSITIVE] + typedef someType<((n - 4) < 0 ? 0 : n - 4)> b; // GOOD }; someType<42>::b someType_x;