Implement Rule 0-0-1, unreachable statements from DeadCode package#1001
Merged
MichaelRFairhurst merged 2 commits intomainfrom Jan 27, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR implements MISRA C++ 2023 Rule 0-0-1, which prohibits unreachable statements in functions. The implementation leverages custom reachability analysis that accounts for MISRA-specific semantics (e.g., both operands of && are reachable) and integrates with exception handling analysis.
Key changes:
- New query
UnreachableStatement.qlimplements MISRA-specific reachability analysis for detecting unreachable code - Refactored catch block shadowing logic into shared
Shadowing.qlllibrary for reuse - Enhanced
UnreachableCode.qllto properly handle compiler-generated Handler blocks in CFG analysis
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| rules.csv | Updated rule metadata to reference DeadCode3 package |
| rule_packages/cpp/DeadCode3.json | New package definition for RULE-0-0-1 query |
| cpp/misra/test/rules/RULE-0-0-1/test.cpp | Comprehensive test cases covering various unreachability scenarios |
| cpp/misra/test/rules/RULE-0-0-1/UnreachableStatement.qlref | Query reference for testing |
| cpp/misra/test/rules/RULE-0-0-1/UnreachableStatement.expected | Expected test results with location issues |
| cpp/misra/src/rules/RULE-0-0-1/UnreachableStatement.ql | Main query implementing MISRA reachability semantics |
| cpp/common/src/codingstandards/cpp/rules/catchblockshadowing/CatchBlockShadowing.qll | Refactored to use shared Shadowing library |
| cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll | Added DeadCode3 package integration |
| cpp/common/src/codingstandards/cpp/exclusions/cpp/DeadCode3.qll | Auto-generated exclusions file for DeadCode3 package |
| cpp/common/src/codingstandards/cpp/exceptions/Shadowing.qll | New shared library for catch block shadowing detection |
| cpp/common/src/codingstandards/cpp/deadcode/UnreachableCode.qll | Enhanced to handle Handler blocks correctly |
| cpp/common/src/codingstandards/cpp/ast/Catch.qll | New utility functions for catch block analysis |
| change_notes/2025-12-15-update-catch-block-shadowing-dead-code.md | Change note with spelling error |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
change_notes/2025-12-15-update-catch-block-shadowing-dead-code.md
Outdated
Show resolved
Hide resolved
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.
Description
Implement Rule 0-0-1
Change request type
.ql,.qll,.qlsor unit tests)Rules with added or modified queries
RULE-0-0-1M0-1-1RULE-2-1M15-3-6ERR54-CPPRelease change checklist
A change note (development_handbook.md#change-notes) is required for any pull request which modifies:
If you are only adding new rule queries, a change note is not required.
Author: Is a change note required?
🚨🚨🚨
Reviewer: Confirm that format of shared queries (not the .qll file, the
.ql file that imports it) is valid by running them within VS Code.
Reviewer: Confirm that either a change note is not required or the change note is required and has been added.
Query development review checklist
For PRs that add new queries or modify existing queries, the following checklist should be completed by both the author and reviewer:
Author
As a rule of thumb, predicates specific to the query should take no more than 1 minute, and for simple queries be under 10 seconds. If this is not the case, this should be highlighted and agreed in the code review process.
Reviewer
As a rule of thumb, predicates specific to the query should take no more than 1 minute, and for simple queries be under 10 seconds. If this is not the case, this should be highlighted and agreed in the code review process.