Skip to content

Respect maybe_unused in unused-variable queries - #22932

Merged
jketema merged 3 commits into
mainfrom
copilot/issue-22928-test-cases
Oct 29, 2026
Merged

jketema merged 3 commits into
mainfrom
copilot/issue-22928-test-cases

Conversation

@jketema

@jketema jketema commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Teach the unused-local and unused-static-variable queries to honor the C++17 [[maybe_unused]] attribute. Add minimal local and static regression cases with generated expected results.

Fixes part of #22928.

Validation: both affected CodeQL query tests pass with CodeQL CLI 2.27.3.

@github-actions github-actions Bot added the C++ label Oct 29, 2026
@jketema
jketema force-pushed the copilot/issue-22928-test-cases branch 2 times, most recently from 28c0dd9 to 762920a Compare October 29, 2026 10:23
Cover C++17 maybe_unused local and static variables in the unused-variable query tests. Record the current alerts as spurious so the regression cases pass until the queries account for the standard attribute.

Co-authored-by: Copilot <[email protected]>
@jketema
jketema force-pushed the copilot/issue-22928-test-cases branch from 762920a to 6e75b96 Compare October 29, 2026 10:23
Exclude variables annotated with the standard maybe_unused attribute from the unused-local and unused-static-variable queries, and update the regression expectations.

Co-authored-by: Copilot <[email protected]>
@jketema jketema changed the title Add unused-variable regression cases Respect maybe_unused in unused-variable queries Oct 29, 2026
Note that the unused-local and unused-static-variable queries no longer report variables marked with the C++17 maybe_unused attribute.

Co-authored-by: Copilot <[email protected]>
@jketema
jketema force-pushed the copilot/issue-22928-test-cases branch from 33758f2 to 7b47e9b Compare October 29, 2026 10:30
@jketema
jketema marked this pull request as ready for review October 29, 2026 10:47
Copilot AI auto review requested due to automatic review settings October 29, 2026 10:47
@jketema
jketema requested a review from a team as a code owner October 29, 2026 10:47

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

The update to honor C++17 [[maybe_unused]] in unused-variable queries has no active review issues.

No open issues 🎉

What changed in this PR

Updates the C++ unused-variable queries to respect C++17 [[maybe_unused]], addressing the annotation-related portion of #22928 without changing side-effect handling.

Changes:

  • Excludes explicitly annotated variables from both unused-local and unused-static-variable results.
  • Adds local and static regression cases, enabling C++17 for the static-variable test.
  • Adds a change note describing the reduced false positives.
File Description
cpp/​ql/​test/​query-tests/​Best Practices/​Unused Entities/​UnusedStaticVariables/​test.cpp Enables C++17 and adds an annotated static-variable regression case.
cpp/​ql/​test/​query-tests/​Best Practices/​Unused Entities/​UnusedLocals/​code2.cpp Adds an annotated local-variable regression case.
cpp/​ql/​src/​change-notes/​2026-10-29-unused-maybe-unused.md Documents the updated query behavior.
cpp/​ql/​src/​Best Practices/​Unused Entities/​UnusedStaticVariables.ql Exempts static variables marked maybe_unused.
cpp/​ql/​src/​Best Practices/​Unused Entities/​UnusedLocals.ql Exempts local variables marked maybe_unused.

Review effort: Balanced (auto)

@hvitved hvitved 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

@jketema

jketema commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

DCA was uneventful

@jketema
jketema merged commit 835afbb into main Oct 29, 2026
22 checks passed
@jketema
jketema deleted the copilot/issue-22928-test-cases branch October 29, 2026 14:24
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.

3 participants