Skip to content

Commit b2082cc

Browse files
committed
C++: Fix false positive in 'cpp/cpp/comparison-of-identical-expressions'.
1 parent 9d14a85 commit b2082cc

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

cpp/ql/src/Likely Bugs/Arithmetic/PointlessSelfComparison.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ predicate pointlessSelfComparison(ComparisonOperation cmp) {
2929
not exists(lhs.getQualifier()) and // Avoid structure fields
3030
not exists(rhs.getQualifier()) and // Avoid structure fields
3131
not convertedExprMightOverflow(lhs) and
32-
not convertedExprMightOverflow(rhs)
32+
not convertedExprMightOverflow(rhs) and
33+
// Don't warn if the comparison is part of a template argument.
34+
not any(ClassTemplateInstantiation inst).getATemplateArgument() = cmp.getParent*()
3335
)
3436
}
3537

cpp/ql/test/query-tests/Likely Bugs/Arithmetic/BadAdditionOverflowCheck/PointlessSelfComparison.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
| templates.cpp:17:5:17:25 | ... < ... | Self comparison. |
2-
| templates.cpp:31:20:31:41 | ... <= ... | Self comparison. |
32
| test.cpp:13:11:13:21 | ... == ... | Self comparison. |
43
| test.cpp:79:11:79:32 | ... == ... | Self comparison. |
54
| test.cpp:83:10:83:15 | ... == ... | Self comparison. |

0 commit comments

Comments
 (0)