Implement package exceptions3 for MISRA C++#901
Merged
MichaelRFairhurst merged 6 commits intomainfrom Dec 9, 2025
Merged
Conversation
Adds support for: - RULE-18-3-1 - RULE-18-3-2 - RULE-18-4-1
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a new “Exceptions3” package for MISRA C++ exception rules, adding three new rules (18-3-1, 18-3-2, 18-4-1) along with tests, query implementations, and metadata updates.
- Added unit tests (.cpp, .qlref, .expected) covering four variants of rule 18-3-1.
- Introduced CodeQL queries for RULE-18-3-1 (missing catch-all in main), RULE-18-3-2 (class exceptions caught by value), and RULE-18-4-1 (exception-unfriendly functions must be noexcept).
- Updated exclusion metadata (RuleMetadata.qll, Exceptions3.qll) and supporting QLL libraries (ExceptionFlow, Function, SpecialFunctionExceptions).
Reviewed Changes
Copilot reviewed 33 out of 33 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| cpp/misra/test/rules/RULE-18-3-1.4/test_except_inside_catch.cpp | Add NON-COMPLIANT test where cout in catch-all may throw |
| cpp/misra/test/rules/RULE-18-3-1.4/MissingCatchAllExceptionHandlerInMain.qlref | Reference the new 18-3-1.4 test for the missing-catch rule |
| cpp/misra/test/rules/RULE-18-3-1.4/MissingCatchAllExceptionHandlerInMain.expected | Add expected alert for test_except_inside_catch.cpp |
| cpp/misra/test/rules/RULE-18-3-1.3/test_except_after_catch.cpp | Add NON-COMPLIANT test where f() after catch may throw |
| cpp/misra/test/rules/RULE-18-3-1.3/MissingCatchAllExceptionHandlerInMain.qlref | Reference the new 18-3-1.3 test for the missing-catch rule |
| cpp/misra/test/rules/RULE-18-3-1.3/MissingCatchAllExceptionHandlerInMain.expected | Add expected alert for test_except_after_catch.cpp |
| cpp/misra/test/rules/RULE-18-3-1.2/test_except_before_catch.cpp | Add NON-COMPLIANT test where f() before catch may throw |
| cpp/misra/test/rules/RULE-18-3-1.2/MissingCatchAllExceptionHandlerInMain.qlref | Reference the new 18-3-1.2 test for the missing-catch rule |
| cpp/misra/test/rules/RULE-18-3-1.2/MissingCatchAllExceptionHandlerInMain.expected | Add expected alert for test_except_before_catch.cpp |
| cpp/misra/test/rules/RULE-18-3-1.1/test_missing.cpp | Add NON-COMPLIANT test with no catch-all handler |
| cpp/misra/test/rules/RULE-18-3-1.1/MissingCatchAllExceptionHandlerInMain.qlref | Reference the new 18-3-1.1 test for the missing-catch rule |
| cpp/misra/test/rules/RULE-18-3-1.1/MissingCatchAllExceptionHandlerInMain.expected | Add expected alert for test_missing.cpp |
| cpp/misra/src/rules/RULE-18-4-1/ExceptionUnfriendlyFunctionMustBeNoexcept.ql | Implement query for exception-unfriendly functions needing noexcept |
| cpp/misra/src/rules/RULE-18-3-2/ClassExceptionCaughtByValue.ql | Implement query to enforce catching classes by (const) reference |
| cpp/misra/src/rules/RULE-18-3-1/MissingCatchAllExceptionHandlerInMain.ql | Implement catch-all-in-main query with custom predicate |
| cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll | Import new Exceptions3 package in exclusion metadata |
| cpp/common/src/codingstandards/cpp/exclusions/cpp/Exceptions3.qll | Auto-generate Exceptions3Query type and metadata checks |
| cpp/common/src/codingstandards/cpp/exceptions/ExceptionFlow.qll | Add helper getATryStmt to locate enclosing try blocks |
| cpp/common/src/codingstandards/cpp/exceptions/Function.qll | Add UserDeclaredFunction and function-access-like classes |
| cpp/common/src/codingstandards/cpp/exceptions/SpecialFunctionExceptions.qll | Extend special-function exception descriptions and contexts |
Comments suppressed due to low confidence (2)
cpp/common/src/codingstandards/cpp/exceptions/SpecialFunctionExceptions.qll:18
- [nitpick] Remove or consolidate the redundant import of
ExceptionFlow, since it’s also imported with a fully-qualified path.
private import ExceptionFlow
cpp/common/src/codingstandards/cpp/exceptions/SpecialFunctionExceptions.qll:107
- [nitpick] Adjust indentation of the closing brace to align with the opening brace for consistency.
}
cpp/misra/src/rules/RULE-18-4-1/ExceptionUnfriendlyFunctionMustBeNoexcept.ql
Outdated
Show resolved
Hide resolved
cpp/common/src/codingstandards/cpp/exceptions/ExceptionFlow.qll
Outdated
Show resolved
Hide resolved
mbaluda
approved these changes
Dec 4, 2025
Collaborator
mbaluda
left a comment
There was a problem hiding this comment.
Super interesting stuff, LGTM!
Just a few minor comments below
cpp/misra/src/rules/RULE-18-3-1/MissingCatchAllExceptionHandlerInMain.ql
Outdated
Show resolved
Hide resolved
cpp/misra/src/rules/RULE-18-3-1/MissingCatchAllExceptionHandlerInMain.ql
Outdated
Show resolved
Hide resolved
cpp/common/src/codingstandards/cpp/exceptions/SpecialFunctionExceptions.qll
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
Misra C++ exceptions rules
Change request type
.ql,.qll,.qlsor unit tests)Rules with added or modified queries
Release 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.