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

Skip to content

Commit e7f19e9

Browse files
committed
CPP: Add a test of UnusedStaticVariable.ql.
1 parent 3c00d4b commit e7f19e9

3 files changed

Lines changed: 22 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| test.cpp:7:12:7:21 | staticVar5 | Static variable staticVar5 is never read |
2+
| test.cpp:8:12:8:21 | staticVar6 | Static variable staticVar6 is never read |
3+
| test.cpp:9:40:9:49 | staticVar7 | Static variable staticVar7 is never read |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Best Practices/Unused Entities/UnusedStaticVariables.ql
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
int globalVar; // GOOD (not static)
3+
static int staticVar1; // GOOD (used)
4+
static int staticVar2; // GOOD (used)
5+
static int staticVar3 = 3; // GOOD (used)
6+
static int staticVar4 = staticVar3; // GOOD (used)
7+
static int staticVar5; // BAD (unused)
8+
static int staticVar6 = 6; // BAD (unused)
9+
static __attribute__((__unused__)) int staticVar7; // GOOD (unused but this is expected) [FALSE POSITIVE]
10+
11+
void f()
12+
{
13+
int *ptr = &staticVar4;
14+
15+
staticVar1 = staticVar2;
16+
(*ptr) = 0;
17+
}
18+

0 commit comments

Comments
 (0)