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

Skip to content

Commit 73b186a

Browse files
committed
CPP: Add test case.
1 parent 2846d80 commit 73b186a

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/ExprHasNoEffect.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
| preproc.c:89:2:89:4 | call to fn4 | This expression has no effect (because $@ has no external side effects). | preproc.c:33:5:33:7 | fn4 | fn4 |
22
| preproc.c:94:2:94:4 | call to fn9 | This expression has no effect (because $@ has no external side effects). | preproc.c:78:5:78:7 | fn9 | fn9 |
3+
| template.cpp:4:3:4:3 | call to operator++ | This expression has no effect (because $@ has no external side effects). | template.cpp:9:10:9:19 | operator++ | operator++ |
4+
| template.cpp:19:3:19:3 | call to operator++ | This expression has no effect (because $@ has no external side effects). | template.cpp:9:10:9:19 | operator++ | operator++ |
35
| test.c:7:5:7:5 | 0 | This expression has no effect. | test.c:7:5:7:5 | 0 | |
46
| test.c:9:8:9:8 | 1 | This expression has no effect. | test.c:9:8:9:8 | 1 | |
57
| test.c:9:11:9:11 | 2 | This expression has no effect. | test.c:9:11:9:11 | 2 | |
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
template<class T>
3+
void Increment(T &t) {
4+
t++; // GOOD (sometimes has an effect) [FALSE POSITIVE]
5+
}
6+
7+
class Nothing {
8+
public:
9+
Nothing operator++(int) {
10+
return *this; // do nothing
11+
}
12+
};
13+
14+
void myTemplateTest() {
15+
int i = 0;
16+
Nothing n;
17+
18+
i++; // GOOD (always has an effect)
19+
n++; // BAD (never has an effect)
20+
Increment(i);
21+
Increment(n);
22+
}

0 commit comments

Comments
 (0)