Skip to content

Commit 97cc0eb

Browse files
committed
C++: Suppress PointlessSelfComparison on templates
It's a bit crude to suppress all results in instantiations, but we're already using this kind of suppression in `PointlessComparison.ql` (without the `Self`) because there is no convenient alternative. It means we lose some good results but also suppress a new false positive in Boost that surfaced after we added support for non-type template parameters.
1 parent 281d512 commit 97cc0eb

File tree

3 files changed

+4
-8
lines changed

3 files changed

+4
-8
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ where
1919
pointlessSelfComparison(cmp) and
2020
not nanTest(cmp) and
2121
not overflowTest(cmp) and
22+
not cmp.isFromTemplateInstantiation(_) and
2223
not exists(MacroInvocation mi |
2324
// cmp is in mi
2425
mi.getAnExpandedElement() = cmp and

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
| templates.cpp:20:5:20:25 | ... < ... | Self comparison. |
2-
| templates.cpp:21:5:21:25 | ... < ... | Self comparison. |
3-
| templates.cpp:21:5:21:25 | ... < ... | Self comparison. |
4-
| templates.cpp:22:5:22:25 | ... < ... | Self comparison. |
5-
| templates.cpp:22:5:22:25 | ... < ... | Self comparison. |
6-
| templates.cpp:22:5:22:25 | ... < ... | Self comparison. |
1+
| templates.cpp:17:5:17:25 | ... < ... | Self comparison. |
72
| test.cpp:13:11:13:21 | ... == ... | Self comparison. |
83
| test.cpp:79:11:79:32 | ... == ... | Self comparison. |
94
| test.cpp:83:10:83:15 | ... == ... | Self comparison. |

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ bool compareValues() {
1212
// all instantiations in the program, there could still be more such
1313
// instantiations outside.
1414
return
15-
T1::value < T2::value || // GOOD [FALSE POSITIVE]
16-
T1::value < T1::value || // BAD
15+
T1::value < T2::value || // GOOD
16+
T1::value < T1::value || // BAD [NOT DETECTED]
1717
C1::value < C1::value ; // BAD
1818
}
1919

0 commit comments

Comments
 (0)