Repository navigation
Respect maybe_unused in unused-variable queries - #22932
Merged
Merged
Conversation
jketema
force-pushed
the
copilot/issue-22928-test-cases
branch
2 times, most recently
from
October 29, 2026 10:23
28c0dd9 to
762920a
Compare
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 <223556219+Copilot@users.noreply.github.com>
jketema
force-pushed
the
copilot/issue-22928-test-cases
branch
from
October 29, 2026 10:23
762920a to
6e75b96
Compare
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 <223556219+Copilot@users.noreply.github.com>
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 <223556219+Copilot@users.noreply.github.com>
jketema
force-pushed
the
copilot/issue-22928-test-cases
branch
from
October 29, 2026 10:30
33758f2 to
7b47e9b
Compare
jketema
marked this pull request as ready for review
October 29, 2026 10:47
Contributor
There was a problem hiding this comment.
🟢 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)
Contributor
Author
|
DCA was uneventful |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.