Move M5-14-1 implementation into shared query with Rule 8.14.1, increase test coverage.#1050
Conversation
…ase test coverage.
There was a problem hiding this comment.
Pull request overview
This PR consolidates the implementations of AUTOSAR M5-14-1 and MISRA C++:2023 RULE-8-14-1 into a single shared query, and adjusts tests/package metadata accordingly.
Changes:
- Introduces a shared implementation
ShortCircuitedPersistentSideEffectSharedand rewiresM5-14-1andRULE-8-14-1to use it. - Adds a new rule package/exclusions wiring for
RULE-8-14-1(SideEffects5) and updates RuleMetadata. - Replaces per-rule tests with shared-library-backed tests and expands shared test coverage.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| rule_packages/cpp/SideEffects5.json | Adds new package metadata for MISRA C++ RULE-8-14-1. |
| rule_packages/cpp/SideEffects1.json | Points M5-14-1 to the new shared implementation. |
| cpp/misra/test/rules/RULE-8-14-1/ShortCircuitedPersistentSideEffect.testref | Hooks RULE-8-14-1 tests to the shared test query. |
| cpp/misra/src/rules/RULE-8-14-1/ShortCircuitedPersistentSideEffect.ql | Adds new MISRA query importing the shared implementation. |
| cpp/common/test/rules/shortcircuitedpersistentsideeffectshared/test.cpp | Adds expanded test cases for the shared implementation. |
| cpp/common/test/rules/shortcircuitedpersistentsideeffectshared/ShortCircuitedPersistentSideEffectShared.ql | Shared-implementation test query wrapper (generated). |
| cpp/common/test/rules/shortcircuitedpersistentsideeffectshared/ShortCircuitedPersistentSideEffectShared.expected | Expected results for the shared-implementation tests. |
| cpp/common/src/codingstandards/cpp/rules/shortcircuitedpersistentsideeffectshared/ShortCircuitedPersistentSideEffectShared.qll | New shared query implementation module. |
| cpp/common/src/codingstandards/cpp/exclusions/cpp/SideEffects5.qll | Adds exclusions metadata package module for SideEffects5. |
| cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll | Registers SideEffects5 in exclusions metadata wiring. |
| cpp/autosar/test/rules/M5-14-1/test.cpp | Removes local test file in favor of shared tests. |
| cpp/autosar/test/rules/M5-14-1/RightHandOperandOfALogicalAndOperatorsContainSideEffects.qlref | Removes direct qlref test hook in favor of shared tests. |
| cpp/autosar/test/rules/M5-14-1/RightHandOperandOfALogicalAndOperatorsContainSideEffects.expected | Removes local expected output in favor of shared expected output. |
| cpp/autosar/test/rules/M5-14-1/RightHandOperandOfALogicalAndOperators.testref | Adds shared-test hook for M5-14-1. |
| cpp/autosar/src/rules/M5-14-1/RightHandOperandOfALogicalAndOperatorsContainSideEffects.ql | Replaces inline logic with shared implementation import/config. |
| change_notes/2026-02-21-share-implementation-of-m5-14-1.md | Adds change note for the refactor to shared implementation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| { | ||
| "MISRA-C++-2023": { | ||
| "RULE-8-14-1": { | ||
| "properties": { | ||
| "enforcement": "undecidable", |
There was a problem hiding this comment.
RULE-8-14-1 is mapped to package SideEffects3 in rules.csv (line 901), but this PR introduces a new package file SideEffects5.json for the rule. This mismatch will likely break package generation / rule metadata resolution. Align the package name by updating rules.csv to SideEffects5 (or, if SideEffects3 is intended, rename/regenerate the new rule package/exclusion modules accordingly).
| @@ -0,0 +1 @@ | |||
| cpp/common/test/rules/shortcircuitedpersistentsideeffectshared/ShortCircuitedPersistentSideEffectShared.ql No newline at end of file | |||
There was a problem hiding this comment.
The .testref filename is expected to be <query short_name>.testref (see scripts/generate_rules/generate_package_files.py), but this file is named RightHandOperandOfALogicalAndOperators.testref while the query short name for M5-14-1 is RightHandOperandOfALogicalAndOperatorsContainSideEffects. Rename the file to match the query short name so the test runner/generator can discover it correctly.
| @@ -0,0 +1,27 @@ | |||
| /** | |||
| * @id cpp/misra/short-circuited-persistent-side-effect | |||
| * @name RULE-8-14-1: The right-hand operand of a logical && or operator should not contain persistent side effects | |||
There was a problem hiding this comment.
The query metadata @name says "logical && or operator" but the rule/package title and the @description mention both && and ||. Please update @name to include || as well so metadata is consistent across the rule definition.
| * @name RULE-8-14-1: The right-hand operand of a logical && or operator should not contain persistent side effects | |
| * @name RULE-8-14-1: The right-hand operand of a logical && or || operator should not contain persistent side effects |
| @@ -0,0 +1,2 @@ | |||
| - `M5-14-1` - `RightHandOperandOfALogicalAndOperatorsContainSideEffects.ql`: | |||
| - Implementation has been refactor to share logic with Rule 8.14.1. No observable changes to results expected. No newline at end of file | |||
There was a problem hiding this comment.
Typo/grammar: "has been refactor" should be "has been refactored".
| - Implementation has been refactor to share logic with Rule 8.14.1. No observable changes to results expected. | |
| - Implementation has been refactored to share logic with Rule 8.14.1. No observable changes to results expected. |
| } // COMPLIANT - noexcept operands not evaluated | ||
|
|
||
| if (1 || (typeid(f6()) == typeid(f5()))) { | ||
| } // NON_COMPLIANT - typeid operands not evaluated, but the ==operator is |
There was a problem hiding this comment.
This comment is incomplete (ends at "but the ==operator is"). Either finish the sentence or remove it to avoid confusion when reading the test case.
| } // NON_COMPLIANT - typeid operands not evaluated, but the ==operator is | |
| } // NON_COMPLIANT - typeid operands are not evaluated, but the == operator is, so its operands are evaluated |
Description
Though test coverage didn't quite indicate it so, these two rules are implemented 100% compatibly.
Change request type
.ql,.qll,.qlsor unit tests)Rules with added or modified queries
RULE-8-14-1M5-14-1Release 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.