Skip to content

Commit 98005ed

Browse files
authored
Merge pull request #641 from geoffw0/exprnoeffect2
CPP: More tests of isSideEffectFree() / ExprHasNoEffect.ql
2 parents a4b3b1e + e7390f3 commit 98005ed

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// semmle-extractor-options: --expect_errors
2+
3+
void functionBeforeError()
4+
{
5+
}
6+
7+
void functionWithError1()
8+
{
9+
aaaaaaaaaa(); // error
10+
}
11+
12+
void functionWithError2()
13+
{
14+
int i = aaaaaaaaaa(); // error
15+
}
16+
17+
void functionAfterError()
18+
{
19+
}

cpp/ql/test/library-tests/sideEffects/functions/sideEffects.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
| cpp.cpp:87:5:87:26 | functionAccessesStatic | int | false |
4444
| cpp.cpp:93:6:93:14 | increment | int & -> void | false |
4545
| cpp.cpp:97:6:97:16 | doIncrement | void | false |
46+
| error.cpp:3:6:3:24 | functionBeforeError | void | true |
47+
| error.cpp:7:6:7:23 | functionWithError1 | void | false |
48+
| error.cpp:12:6:12:23 | functionWithError2 | void | false |
49+
| error.cpp:17:6:17:23 | functionAfterError | void | true |
4650
| file://:0:0:0:0 | operator= | __va_list_tag & | false |
4751
| file://:0:0:0:0 | operator= | __va_list_tag & | false |
4852
| sideEffects.c:4:5:4:6 | f1 | int | true |

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
| calls.cpp:8:5:8:5 | 1 | This expression has no effect. | calls.cpp:8:5:8:5 | 1 | |
22
| calls.cpp:12:5:12:16 | call to thingy | This expression has no effect (because $@ has no external side effects). | calls.cpp:7:15:7:20 | thingy | thingy |
3+
| expr.cpp:8:2:8:2 | 0 | This expression has no effect. | expr.cpp:8:2:8:2 | 0 | |
4+
| expr.cpp:9:7:9:7 | 0 | This expression has no effect. | expr.cpp:9:7:9:7 | 0 | |
5+
| expr.cpp:10:2:10:5 | ... , ... | This expression has no effect. | expr.cpp:10:2:10:5 | ... , ... | |
36
| 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 |
47
| 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 |
58
| 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++ |
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace Expr {
2+
3+
int i;
4+
5+
void comma_expr_test()
6+
{
7+
i++, i++; // GOOD
8+
0, i++; // BAD (first part)
9+
i++, 0; // BAD (second part)
10+
0, 0; // BAD (whole)
11+
}
12+
13+
}

0 commit comments

Comments
 (0)