Skip to content

Commit 281d512

Browse files
committed
C++: Add tests for self-comparison template FP
1 parent 717490b commit 281d512

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
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. |
17
| test.cpp:13:11:13:21 | ... == ... | Self comparison. |
28
| test.cpp:79:11:79:32 | ... == ... | Self comparison. |
39
| test.cpp:83:10:83:15 | ... == ... | Self comparison. |
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
struct C1 {
2+
static const int value = 5;
3+
};
4+
5+
struct C2 {
6+
static const int value = 6;
7+
};
8+
9+
template<typename T1, typename T2>
10+
bool compareValues() {
11+
// Not all instantiations have T1 and T2 equal. Even if that's the case for
12+
// all instantiations in the program, there could still be more such
13+
// instantiations outside.
14+
return
15+
T1::value < T2::value || // GOOD [FALSE POSITIVE]
16+
T1::value < T1::value || // BAD
17+
C1::value < C1::value ; // BAD
18+
}
19+
20+
bool callCompareValues() {
21+
return compareValues<C1, C2> || compareValues<C1, C1>();
22+
}

0 commit comments

Comments
 (0)