Skip to content

Commit 73b7b98

Browse files
committed
CPP: Add to UnusedStaticVariables tests.
1 parent 5441352 commit 73b7b98

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
| test.cpp:7:12:7:21 | staticVar5 | Static variable staticVar5 is never read |
22
| test.cpp:8:12:8:21 | staticVar6 | Static variable staticVar6 is never read |
3+
| test.cpp:10:11:10:19 | constVar8 | Static variable constVar8 is never read |
4+
| test.cpp:12:12:12:22 | staticVar10 | Static variable staticVar10 is never read |

cpp/ql/test/query-tests/Best Practices/Unused Entities/UnusedStaticVariables/test.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ static int staticVar4 = staticVar3; // GOOD (used)
77
static int staticVar5; // BAD (unused)
88
static int staticVar6 = 6; // BAD (unused)
99
static __attribute__((__unused__)) int staticVar7; // GOOD (unused but this is expected)
10+
const int constVar8 = 8; // BAD (const defaults to static)
11+
extern const int constVar9 = 9; // GOOD
12+
static int staticVar10 = 10; // GOOD [FALSE POSITIVE] (referenced in a never instantiated template)
1013

1114
void f()
1215
{
@@ -16,3 +19,12 @@ void f()
1619
(*ptr) = 0;
1720
}
1821

22+
template<class T>
23+
class MyTemplateClass // never instantiated
24+
{
25+
public:
26+
MyTemplateClass(int param = staticVar10)
27+
{
28+
// ...
29+
}
30+
};

0 commit comments

Comments
 (0)