Skip to content

Commit 950734f

Browse files
authored
Merge pull request #22961 from github/copilot/unused-static-empty-pack-22931
C++: Ignore compiler-generated variables in unused-static-variable query
2 parents 1a8dbb2 + a5e0a2d commit 950734f

3 files changed

Lines changed: 13 additions & 1 deletion

File tree

‎cpp/ql/src/Best Practices/Unused Entities/UnusedStaticVariables.ql‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ predicate declarationHasSideEffects(Variable v) {
2222
from Variable v
2323
where
2424
v.isStatic() and
25+
not v.isCompilerGenerated() and
2526
v.hasDefinition() and
2627
not v.isConstexpr() and
2728
not exists(VariableAccess a | a.getTarget() = v) and
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The `cpp/unused-static-variable` query no longer reports compiler-generated variables, such as placeholders for empty function parameter packs.

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// semmle-extractor-options: -std=c++17
1+
// semmle-extractor-options: -std=c++20
22
int globalVar; // GOOD (not static)
33
static int staticVar1; // GOOD (used)
44
static int staticVar2; // GOOD (used)
@@ -49,3 +49,10 @@ struct WithDestructor
4949

5050
static WithConstructor constructed; // GOOD (constructor has a side effect)
5151
static WithDestructor destructed; // GOOD (destructor has a side effect)
52+
53+
static auto sum(auto... values)
54+
{
55+
return (0 + ... + values);
56+
}
57+
58+
int globalVar2 = sum() + sum(2);

0 commit comments

Comments
 (0)