Skip to content

Commit a5e0a2d

Browse files
jketemaCopilot
andcommitted
Ignore compiler-generated unused static variables
Exclude synthetic variables from cpp/unused-static-variable so empty parameter pack placeholders do not trigger alerts. Update the regression expectation and document the analysis change. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent b43b7c3 commit a5e0a2d

4 files changed

Lines changed: 6 additions & 2 deletions

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/UnusedStaticVariables.expected‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22
| test.cpp:8:12:8:21 | staticVar6 | Static variable staticVar6 is never read. |
33
| test.cpp:10:11:10:19 | constVar8 | Static variable constVar8 is never read. |
44
| test.cpp:12:12:12:22 | staticVar10 | Static variable staticVar10 is never read. |
5-
| test.cpp:53:25:53:30 | values | Static variable values is never read. |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ struct WithDestructor
5050
static WithConstructor constructed; // GOOD (constructor has a side effect)
5151
static WithDestructor destructed; // GOOD (destructor has a side effect)
5252

53-
static auto sum(auto... values) // $ SPURIOUS: Alert
53+
static auto sum(auto... values)
5454
{
5555
return (0 + ... + values);
5656
}

0 commit comments

Comments
 (0)