Implement RULE-6-7-2 banning most kinds of global variables#1052
Merged
Implement RULE-6-7-2 banning most kinds of global variables#1052
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request implements MISRA C++ 2023 RULE-6-7-2, which bans the use of most kinds of global variables. The implementation shares constant initialization logic with the existing AUTOSAR rule A3-3-2 by extracting common predicates into a new shared module.
Changes:
- Extracted constant initialization checking predicates from A3-3-2 to a shared module (
Initialization.qll) to enable reuse across multiple rules - Implemented new query RULE-6-7-2 that flags global variables (namespace-scoped or static class members) that are either non-const or not constant-initialized
- Added required infrastructure including package metadata, exclusion modules, and comprehensive test cases
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| rules.csv | Added entry for RULE-6-7-2 mapping it to the Banned1 package |
| rule_packages/cpp/Banned1.json | New package metadata defining query properties for RULE-6-7-2 |
| cpp/misra/test/rules/RULE-6-7-2/test.cpp | Comprehensive test cases covering compliant and non-compliant global variable scenarios |
| cpp/misra/test/rules/RULE-6-7-2/GlobalVariableUsed.qlref | Test reference file pointing to the query implementation |
| cpp/misra/test/rules/RULE-6-7-2/GlobalVariableUsed.expected | Expected test results with 8 non-compliant cases |
| cpp/misra/src/rules/RULE-6-7-2/GlobalVariableUsed.ql | Main query implementation detecting non-const or non-constant-initialized global variables |
| cpp/common/src/codingstandards/cpp/orderofevaluation/Initialization.qll | Shared module containing extracted constant initialization checking logic |
| cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll | Updated to register the new Banned1 package |
| cpp/common/src/codingstandards/cpp/exclusions/cpp/Banned1.qll | Auto-generated exclusion module for the Banned1 package |
| cpp/autosar/src/rules/A3-3-2/StaticOrThreadLocalObjectsNonConstantInit.ql | Refactored to import shared initialization logic instead of duplicating it |
| change_notes/2026-02-22-shared-default-initialization-logic.md | Change note documenting the refactoring of A3-3-2 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
Fairly straightforward implementation, shared initialization logic with prior rule
A3-3-2.Change request type
.ql,.qll,.qlsor unit tests)Rules with added or modified queries
RULE-6-7-2A3-3-2Release 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.