Queued
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
Adds a new “preprocessor2” package with MISRA C++ queries for include directives, macro argument parenthesis, and pragma usage, along with supporting changes to the matching‐parenthesis and macro utilities.
- Introduce three new queries for RULE-19-2-2 (invalid
#include), RULE-19-3-4 (unparenthesized macro arguments), and RULE-19-6-1 (disallowed#pragma). - Extend
MatchingParenthesisto handle end‐of‐input and addparameterPrecedenceUnprotectedtoMacro.qll. - Update exclusion metadata and add
.qlref/.expectedtest definitions for the three new rules.
Reviewed Changes
Copilot reviewed 50 out of 50 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| cpp/misra/src/rules/RULE-19-2-2/InvalidIncludeDirective.ql | New query to enforce <file> or "file" syntax in #include |
| cpp/misra/src/rules/RULE-19-3-4/UnparenthesizedMacroArgument.ql | New query to flag macro arguments missing parentheses around critical operators |
| cpp/misra/src/rules/RULE-19-6-1/DisallowedUseOfPragma.ql | New query disallowing #pragma and _Pragma usage |
| cpp/common/src/codingstandards/cpp/MatchingParenthesis.qll | Regex update to support end‐of‐input in parenthesis matching |
| cpp/common/src/codingstandards/cpp/Macro.qll | Added parameterPrecedenceUnprotected predicate |
| cpp/common/src/codingstandards/cpp/exclusions/cpp/Preprocessor2.qll | Exclusion metadata for new queries |
| cpp/misra/test/rules/RULE-19-1-1/*.expected & *.qlref | Added expected outputs and refs for defined‐operator tests |
Comments suppressed due to low confidence (1)
cpp/misra/src/rules/RULE-19-2-2/InvalidIncludeDirective.ql:1
- No unit tests provided for this new query (and similarly for RULE-19-3-4 and RULE-19-6-1). Please add compliant and non-compliant test cases under
cpp/misra/test/rulesfor full coverage.
/**
Collaborator
Author
|
19-3-4 could also be used to implement: |
…implement-package-preprocessor2
…implement-package-preprocessor2
…age-preprocessor' into implement-package-preprocessor2
…age-preprocessor' into implement-package-preprocessor2
…age-preprocessor' into implement-package-preprocessor2
cpp/misra/src/rules/RULE-19-3-4/UnparenthesizedMacroArgument.ql
Outdated
Show resolved
Hide resolved
cpp/misra/src/rules/RULE-19-3-4/UnparenthesizedMacroArgument.ql
Outdated
Show resolved
Hide resolved
cpp/misra/src/rules/RULE-19-3-4/UnparenthesizedMacroArgument.ql
Outdated
Show resolved
Hide resolved
cpp/misra/src/rules/RULE-19-3-4/UnparenthesizedMacroArgument.ql
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
mbaluda
approved these changes
Mar 4, 2026
Any commits made after this event will not be merged.
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 package preprocessor2. Builds on #893
Rule 19-3-4 has a number of reports in popular repositories that are not false positives by the rule text:
#define M(X, Y) f(X, Y)which do not need parenthesis but the rule text disallows#define M1(..., X, ...) ... (X) ...,#define M2(X) M1(..., X, ...)whether this violates the rule by text is ambiguous. This is a subset of the above case. Very difficult to detect.M(arr[1 * 1])is non-compliant by rule text but clearly safe.MatchingParenthesismodule could be extended to exclude these findings, with additional work.#define M(X) {X;}The matching parenthesis parser is does not have error recovery. There are potentially false negatives when parenthesis are unbalanced, but
Adding error recovery would likely be a modest amount of work. An easier solution, though it still suffers from the same two above problems, would be a recursive
getDepthfunction that matches the behavior described in the rule text (depth +1 on '(', depth - 1 on ')', depth unchanged otherwise).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.