Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 383dafa

Browse files
committed
C++: Test for UnsignedGEZero with templates
1 parent 3e022ad commit 383dafa

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
template<typename T>
2+
bool sometimesPointless(T param) {
3+
return param >= 0; // GOOD (FALSE POSITIVE: hypothetical instantiations are okay)
4+
}
5+
6+
template<typename T>
7+
bool alwaysPointless(T param) {
8+
unsigned int local = param;
9+
return local >= 0; // BAD (in all instantiations)
10+
}
11+
12+
static int caller(int i) {
13+
return
14+
sometimesPointless<unsigned int>(i) ||
15+
alwaysPointless<unsigned int>(i) ||
16+
alwaysPointless<int>(i);
17+
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
| Templates.cpp:3:10:3:19 | ... >= ... | Pointless comparison of unsigned value to zero. |
2+
| Templates.cpp:9:10:9:19 | ... >= ... | Pointless comparison of unsigned value to zero. |
3+
| Templates.cpp:9:10:9:19 | ... >= ... | Pointless comparison of unsigned value to zero. |
4+
| Templates.cpp:9:10:9:19 | ... >= ... | Pointless comparison of unsigned value to zero. |
15
| UnsignedGEZero.c:40:6:40:12 | ... >= ... | Pointless comparison of unsigned value to zero. |
26
| UnsignedGEZero.c:48:6:48:15 | ... >= ... | Pointless comparison of unsigned value to zero. |
37
| UnsignedGEZero.c:54:6:54:12 | ... >= ... | Pointless comparison of unsigned value to zero. |

0 commit comments

Comments
 (0)