CPP: Add a test of UnusedStaticVariable.ql.

This commit is contained in:
Geoffrey White
2018-12-05 09:53:58 +00:00
parent 3c00d4be6d
commit e7f19e97cb
3 changed files with 22 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
| test.cpp:7:12:7:21 | staticVar5 | Static variable staticVar5 is never read |
| test.cpp:8:12:8:21 | staticVar6 | Static variable staticVar6 is never read |
| test.cpp:9:40:9:49 | staticVar7 | Static variable staticVar7 is never read |

View File

@@ -0,0 +1 @@
Best Practices/Unused Entities/UnusedStaticVariables.ql

View File

@@ -0,0 +1,18 @@
int globalVar; // GOOD (not static)
static int staticVar1; // GOOD (used)
static int staticVar2; // GOOD (used)
static int staticVar3 = 3; // GOOD (used)
static int staticVar4 = staticVar3; // GOOD (used)
static int staticVar5; // BAD (unused)
static int staticVar6 = 6; // BAD (unused)
static __attribute__((__unused__)) int staticVar7; // GOOD (unused but this is expected) [FALSE POSITIVE]
void f()
{
int *ptr = &staticVar4;
staticVar1 = staticVar2;
(*ptr) = 0;
}