Skip to content

Commit aee2af7

Browse files
committed
CPP: Add a test of ExprHasNoEffect.ql with a call to a 'weak' function.
1 parent cb43d27 commit aee2af7

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

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
@@ -33,3 +33,5 @@
3333
| volatile.c:12:5:12:9 | access to array | This expression has no effect. | volatile.c:12:5:12:9 | access to array | |
3434
| volatile.c:16:5:16:7 | * ... | This expression has no effect. | volatile.c:16:5:16:7 | * ... | |
3535
| volatile.c:20:5:20:13 | * ... | This expression has no effect. | volatile.c:20:5:20:13 | * ... | |
36+
| weak.c:18:2:18:18 | call to myNothingFunction | This expression has no effect (because $@ has no external side effects). | weak.c:2:5:2:21 | myNothingFunction | myNothingFunction |
37+
| weak.c:19:2:19:22 | call to myWeakNothingFunction | This expression has no effect (because $@ has no external side effects). | weak.c:9:31:9:51 | myWeakNothingFunction | myWeakNothingFunction |
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
int myNothingFunction()
3+
{
4+
// does nothing
5+
6+
return 0;
7+
}
8+
9+
int __attribute__((__weak__)) myWeakNothingFunction()
10+
{
11+
// does nothing, but we could be overridden at the linker stage with a non-weak definition
12+
// from elsewhere in the program.
13+
14+
return 0;
15+
}
16+
17+
void testWeak() {
18+
myNothingFunction(); // BAD
19+
myWeakNothingFunction(); // GOOD [FALSE POSITIVE]
20+
}

0 commit comments

Comments
 (0)