Skip to content

C++: Ignore compiler-generated variables in unused-static-variable query - #22961

Merged
jketema merged 2 commits into
mainfrom
copilot/unused-static-empty-pack-22931
Oct 30, 2026
Merged

jketema merged 2 commits into
mainfrom
copilot/unused-static-empty-pack-22931

Conversation

@jketema

@jketema jketema commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #22931.

Exclude compiler-generated variables from cpp/unused-static-variable. Our frontend creates a synthetic static variable as a placeholder for an empty function parameter pack; it is not user-declared storage and should not trigger an unused-variable alert.

The first commit adds a minimal reproducer to the existing UnusedStaticVariables test, capturing the spurious alert. The second commit adds the exclusion, updates the expected result, and includes a change note.

Extend the unused static variable query test with a minimal variadic sum instantiated with empty and non-empty packs. Record the spurious alert on the compiler-generated empty-pack variable reported in #22931.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jketema
jketema force-pushed the copilot/unused-static-empty-pack-22931 branch from bad7a6a to b43b7c3 Compare October 30, 2026 14:49
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>
@jketema jketema changed the title Add empty parameter pack regression test C++: Ignore compiler-generated variables in unused-static-variable query Oct 30, 2026
@jketema
jketema marked this pull request as ready for review October 30, 2026 15:09
@jketema
jketema requested a review from a team as a code owner October 30, 2026 15:09
Copilot AI auto review requested due to automatic review settings October 30, 2026 15:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported, and the change targets false positives with corresponding regression coverage and documentation.

No open issues 🎉

What changed in this PR

Updates cpp/unused-static-variable to ignore compiler-generated variables, preventing false positives for synthetic placeholders created for empty abbreviated parameter packs.

Changes:

  • Adds a C++20 regression test for empty and nonempty abbreviated parameter packs.
  • Excludes compiler-generated variables from the unused-static-variable query.
  • Adds a minor analysis change note.
File Description
cpp/​ql/​test/​query-tests/​Best Practices/​Unused Entities/​UnusedStaticVariables/​test.cpp Adds a C++20 regression case for abbreviated parameter packs.
cpp/​ql/​src/​change-notes/​2026-10-30-unused-static-compiler-generated.md Documents the query behavior change.
cpp/​ql/​src/​Best Practices/​Unused Entities/​UnusedStaticVariables.ql Filters compiler-generated variables from query results.

Review effort: Lite (auto)

@geoffw0 geoffw0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but please check any result changes on DCA look reasonable before merging. 👍

@jketema

jketema commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

Yup, will not merge until I've seen that the DCA results are good.

@jketema

jketema commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

DCA was uneventful.

@jketema
jketema merged commit 950734f into main Oct 30, 2026
22 checks passed
@jketema
jketema deleted the copilot/unused-static-empty-pack-22931 branch October 30, 2026 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

C++ used abbreviated function parameter pack is reported as unread static variable

3 participants