Skip to content

Michaelrfairhurst/declarations 10-1-1 properly qualify lvalue refs pointers#1102

Open
MichaelRFairhurst wants to merge 11 commits intomainfrom
michaelrfairhurst/declarations-10-1-1-properly-qualify-lvalue-refs-pointers
Open

Michaelrfairhurst/declarations 10-1-1 properly qualify lvalue refs pointers#1102
MichaelRFairhurst wants to merge 11 commits intomainfrom
michaelrfairhurst/declarations-10-1-1-properly-qualify-lvalue-refs-pointers

Conversation

@MichaelRFairhurst
Copy link
Copy Markdown
Collaborator

@MichaelRFairhurst MichaelRFairhurst commented Apr 3, 2026

Description

Require const where possible.

Change request type

  • Release or process automation (GitHub workflows, internal scripts)
  • Internal documentation
  • External documentation
  • Query files (.ql, .qll, .qls or unit tests)
  • External scripts (analysis report or other code shipped as part of a release)

Rules with added or modified queries

  • No rules added
  • Queries have been added for the following rules:
    • RULE-10-1-1
  • Queries have been modified for the following rules:
    • rule number here

Release change checklist

A change note (development_handbook.md#change-notes) is required for any pull request which modifies:

  • The structure or layout of the release artifacts.
  • The evaluation performance (memory, execution time) of an existing query.
  • The results of an existing query in any circumstance.

If you are only adding new rule queries, a change note is not required.

Author: Is a change note required?

  • Yes
  • No

🚨🚨🚨
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.

  • Confirmed

Reviewer: Confirm that either a change note is not required or the change note is required and has been added.

  • Confirmed

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

  • Have all the relevant rule package description files been checked in?
  • Have you verified that the metadata properties of each new query is set appropriately?
  • Do all the unit tests contain both "COMPLIANT" and "NON_COMPLIANT" cases?
  • Are the alert messages properly formatted and consistent with the style guide?
  • Have you run the queries on OpenPilot and verified that the performance and results are acceptable?
    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.
  • Does the query have an appropriate level of in-query comments/documentation?
  • Have you considered/identified possible edge cases?
  • Does the query not reinvent features in the standard library?
  • Can the query be simplified further (not golfed!)

Reviewer

  • Have all the relevant rule package description files been checked in?
  • Have you verified that the metadata properties of each new query is set appropriately?
  • Do all the unit tests contain both "COMPLIANT" and "NON_COMPLIANT" cases?
  • Are the alert messages properly formatted and consistent with the style guide?
  • Have you run the queries on OpenPilot and verified that the performance and results are acceptable?
    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.
  • Does the query have an appropriate level of in-query comments/documentation?
  • Have you considered/identified possible edge cases?
  • Does the query not reinvent features in the standard library?
  • Can the query be simplified further (not golfed!)

Copilot AI review requested due to automatic review settings April 3, 2026 23:36
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new MISRA C++:2023 RULE-10-1-1 query that flags pointer/lvalue-reference parameters whose pointee/referent is not modified and therefore can be const-qualified, along with a dedicated test suite and supporting metadata/packaging updates.

Changes:

  • Added new query implementation PointerOrRefParamNotConst.ql for RULE-10-1-1.
  • Added unit tests for the rule, including .qlref and .expected outputs.
  • Added a new rule package descriptor (Declarations6) and wired it into the exclusions metadata; updated test stdlib vector model for const-correct cbegin/cend.
Show a summary per file
File Description
rules.csv Updates rule-to-package mapping for RULE-10-1-1 (currently points to the wrong package).
rule_packages/cpp/Declarations6.json New rule package description file for RULE-10-1-1.
cpp/misra/src/rules/RULE-10-1-1/PointerOrRefParamNotConst.ql New CodeQL query implementing the rule (contains wiring + cleanup/doc issues).
cpp/misra/test/rules/RULE-10-1-1/test.cpp New test cases for compliant/non-compliant parameter usage patterns.
cpp/misra/test/rules/RULE-10-1-1/PointerOrRefParamNotConst.qlref Test query reference to the shipped query.
cpp/misra/test/rules/RULE-10-1-1/PointerOrRefParamNotConst.expected Expected results for the new test suite.
cpp/common/test/includes/standard-library/vector.h Fixes cbegin/cend to be const, supporting the rule’s const-member-call logic.
cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll Registers the new Declarations6 package in query metadata plumbing.
cpp/common/src/codingstandards/cpp/exclusions/cpp/Declarations6.qll New autogenerated exclusions metadata module for the Declarations6 package.

Copilot's findings

  • Files reviewed: 10/10 changed files
  • Comments generated: 10

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new MISRA C++:2023 rule implementation for RULE-10-1-1 to require const on pointer/lvalue-reference parameter target types when the target is not modified, along with supporting metadata and tests.

Changes:

  • Added new query PointerOrRefParamNotConst for RULE-10-1-1, plus unit tests and expected results.
  • Introduced a new rule package Declarations6 and wired it into the exclusions/metadata infrastructure and rules.csv.
  • Added a reusable CallArgumentExpr helper and corrected the test standard-library vector mock to make cbegin/cend const.
Show a summary per file
File Description
rules.csv Routes RULE-10-1-1 to the new Declarations6 package.
rule_packages/cpp/Declarations6.json Adds rule-package metadata for the new RULE-10-1-1 query.
cpp/misra/src/rules/RULE-10-1-1/PointerOrRefParamNotConst.ql New query implementation for detecting missing const on pointee/referent types.
cpp/misra/test/rules/RULE-10-1-1/test.cpp New test corpus with COMPLIANT/NON_COMPLIANT cases for the query.
cpp/misra/test/rules/RULE-10-1-1/PointerOrRefParamNotConst.qlref Test reference to the production query.
cpp/misra/test/rules/RULE-10-1-1/PointerOrRefParamNotConst.expected Expected results for the new test suite.
cpp/common/test/includes/standard-library/vector.h Fixes cbegin/cend signatures to be const for tests.
cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll Registers the new Declarations6 package in query metadata wiring.
cpp/common/src/codingstandards/cpp/exclusions/cpp/Declarations6.qll Adds autogenerated exclusions package module for RULE-10-1-1 query.
cpp/common/src/codingstandards/cpp/Call.qll Adds CallArgumentExpr helper to abstract call-argument/parameter-type lookups.

Copilot's findings

Comments suppressed due to low confidence (2)

cpp/common/src/codingstandards/cpp/Call.qll:48

  • The QLDoc for getParamType() uses "its" where "it is" is intended (and the project QLDoc guidelines avoid contractions). Please rephrase to "whether it is based on...".
  /**
   * Gets the `Type` of the parameter corresponding to this argument, whether its based on the
   * target function or the function pointer type.
   */
  Type getParamType() { result = paramType }

cpp/misra/test/rules/RULE-10-1-1/test.cpp:180

  • p6 /= 0; introduces an unconditional division by zero in the test source. Even though it is test-only, it is still undefined behavior and can cause compilation warnings or toolchain-specific issues. Please use a non-zero divisor while still exercising the intended side effect.
  p4 += 0;
  *p5 *= 0;
  p6 /= 0;
  p7++;
  if (p8) {
  • Files reviewed: 10/10 changed files
  • Comments generated: 3

Comment on lines +21 to +24
/**
* An `Expr` that is used as an argument to a `Call`, and has helpers to handle with the differences
* between `ExprCall` and `FunctionCall` cases.
*/
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The QLDoc for CallArgumentExpr contains awkward/incorrect phrasing ("helpers to handle with the differences"). Please reword this sentence to be grammatically correct and unambiguous.

This issue also appears on line 44 of the same file.

Copilot uses AI. Check for mistakes.
Comment on lines +25 to +32
/**
* Holds if the function is in a template scope and should be excluded.
*/
predicate isInTemplateScope(Function f) {
f.isFromTemplateInstantiation(_)
or
f.isFromUninstantiatedTemplate(_)
}
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The QLDoc for isInTemplateScope should explicitly mention its parameter f (the project's QLDoc style requires documenting predicate parameters). Consider rephrasing to "Holds if f is in a template scope and should be excluded."

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants