Skip to content

Declarations2 MISRA2023 CPP#1097

Open
knewbury01 wants to merge 6 commits intogithub:mainfrom
knewbury01:knewbury01/cpp-misra2023-declarations2
Open

Declarations2 MISRA2023 CPP#1097
knewbury01 wants to merge 6 commits intogithub:mainfrom
knewbury01:knewbury01/cpp-misra2023-declarations2

Conversation

@knewbury01
Copy link
Copy Markdown
Collaborator

@knewbury01 knewbury01 commented Mar 27, 2026

Description

Add rule RULE-6-2-2 and translate to a shared rule with DCL40-C, improve testing based on cpp nuances

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-6-2-2
    • RULE-6-7-1
  • Queries have been modified for the following rules:
    • DCL40-C

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!)

@knewbury01 knewbury01 self-assigned this Mar 30, 2026
@knewbury01 knewbury01 marked this pull request as ready for review March 30, 2026 19:18
Copilot AI review requested due to automatic review settings March 30, 2026 19:18
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 MISRA C++:2023 coverage for additional declaration rules by introducing RULE-6-2-2 and RULE-6-7-1 queries, and refactors CERT DCL40-C to reuse new shared implementations with updated/expanded tests.

Changes:

  • Added MISRA C++:2023 queries for RULE-6-2-2 (incompatible declarations) and RULE-6-7-1 (local static storage duration).
  • Introduced shared C++ rule implementations for incompatible object/function declarations and wired them into MISRA/CERT queries and exclusion metadata.
  • Updated/added tests and test references to validate the new shared implementations across C, C++, MISRA, and CERT.

Reviewed changes

Copilot reviewed 41 out of 43 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
rules.csv Adjusts rule-to-package mapping for MISRA C++:2023 rules touched by this PR.
rule_packages/cpp/Declarations2.json Adds rule-package metadata for new MISRA C++:2023 queries (RULE-6-2-2, RULE-6-7-1).
rule_packages/c/Declarations2.json Adds shared-implementation metadata fields to align C rule packaging with shared implementations.
cpp/misra/test/rules/RULE-6-7-1/test.cpp New unit test for local static-storage-duration rule behavior.
cpp/misra/test/rules/RULE-6-7-1/LocalVariableStaticStorageDuration.qlref Test harness reference for the RULE-6-7-1 query.
cpp/misra/test/rules/RULE-6-7-1/LocalVariableStaticStorageDuration.expected Expected results for RULE-6-7-1 test.
cpp/misra/test/rules/RULE-6-2-2/IncompatibleObjectDeclarationsCpp.testref Points RULE-6-2-2 object-declaration test to shared/common tests.
cpp/misra/test/rules/RULE-6-2-2/IncompatibleObjectDeclarations.testref Additional test reference for shared object-declaration tests.
cpp/misra/test/rules/RULE-6-2-2/IncompatibleFunctionDeclarationsCpp.testref Points RULE-6-2-2 function-declaration test to shared/common tests.
cpp/misra/test/rules/RULE-6-2-2/IncompatibleFunctionDeclarations.testref Additional test reference for shared function-declaration tests.
cpp/misra/src/rules/RULE-6-7-1/LocalVariableStaticStorageDuration.ql New MISRA C++:2023 RULE-6-7-1 query implementation.
cpp/misra/src/rules/RULE-6-2-2/IncompatibleObjectDeclarationsCpp.ql New MISRA C++:2023 RULE-6-2-2 object-declaration query using shared module.
cpp/misra/src/rules/RULE-6-2-2/IncompatibleFunctionDeclarationsCpp.ql New MISRA C++:2023 RULE-6-2-2 function-declaration query using shared module.
cpp/common/test/rules/incompatibleobjectdeclaration/test1.cpp New shared C++ test input for incompatible object declarations.
cpp/common/test/rules/incompatibleobjectdeclaration/test.cpp New shared C++ test input for incompatible object declarations.
cpp/common/test/rules/incompatibleobjectdeclaration/IncompatibleObjectDeclaration.ql Generated test query wiring for shared object-declaration logic.
cpp/common/test/rules/incompatibleobjectdeclaration/IncompatibleObjectDeclaration.expected Expected results for shared C++ object-declaration tests.
cpp/common/test/rules/incompatiblefunctiondeclaration/test1.cpp New shared C++ test input for incompatible function declarations.
cpp/common/test/rules/incompatiblefunctiondeclaration/test.cpp New shared C++ test input for incompatible function declarations.
cpp/common/test/rules/incompatiblefunctiondeclaration/IncompatibleFunctionDeclaration.ql Generated test query wiring for shared function-declaration logic.
cpp/common/test/rules/incompatiblefunctiondeclaration/IncompatibleFunctionDeclaration.expected Expected results for shared C++ function-declaration tests.
cpp/common/src/codingstandards/cpp/rules/incompatibleobjectdeclaration/IncompatibleObjectDeclaration.qll Adds shared configurable implementation for incompatible object declarations.
cpp/common/src/codingstandards/cpp/rules/incompatiblefunctiondeclaration/IncompatibleFunctionDeclaration.qll Adds shared configurable implementation for incompatible function declarations.
cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll Registers the new Declarations2 package in C++ exclusion metadata.
cpp/common/src/codingstandards/cpp/exclusions/cpp/Declarations2.qll New autogenerated exclusion/metadata wrapper for the Declarations2 C++ package queries.
change_notes/2026-03-27-update-compatible-objects-DCL40-C.md Adds a change note for DCL40-C behavior/results adjustments.
c/common/test/rules/incompatibleobjectdeclaration/test1.c New shared C test input for incompatible object declarations.
c/common/test/rules/incompatibleobjectdeclaration/test.c New shared C test input for incompatible object declarations.
c/common/test/rules/incompatibleobjectdeclaration/IncompatibleObjectDeclaration.ql Generated test query wiring for shared object-declaration logic (C tests).
c/common/test/rules/incompatibleobjectdeclaration/IncompatibleObjectDeclaration.expected Expected results for shared C object-declaration tests.
c/common/test/rules/incompatiblefunctiondeclaration/test1.c New shared C test input for incompatible function declarations.
c/common/test/rules/incompatiblefunctiondeclaration/test.c New shared C test input for incompatible function declarations.
c/common/test/rules/incompatiblefunctiondeclaration/IncompatibleFunctionDeclaration.ql Generated test query wiring for shared function-declaration logic (C tests).
c/common/test/rules/incompatiblefunctiondeclaration/IncompatibleFunctionDeclaration.expected Expected results for shared C function-declaration tests.
c/cert/test/rules/DCL40-C/IncompatibleObjectDeclarations.testref Retargets CERT DCL40-C object-declaration tests to shared common tests.
c/cert/test/rules/DCL40-C/IncompatibleFunctionDeclarations.testref Retargets CERT DCL40-C function-declaration tests to shared common tests.
c/cert/src/rules/DCL40-C/IncompatibleObjectDeclarations.ql Refactors CERT DCL40-C object-declaration query to use shared implementation.
c/cert/src/rules/DCL40-C/IncompatibleFunctionDeclarations.ql Refactors CERT DCL40-C function-declaration query to use shared implementation.
c/cert/src/rules/DCL40-C/ExternalIdentifiers.qll Removes the now-redundant CERT-specific ExternalIdentifiers helper.
Comments suppressed due to low confidence (1)

c/cert/src/rules/DCL40-C/IncompatibleObjectDeclarations.ql:7

  • The CodeQL query metadata tag is malformed (@ kind). This will likely prevent the query kind from being parsed correctly. Please change it to the standard @kind problem (no space after @).
 *              types, then accessing those objects can lead to undefined behaviour.
 * @kind problem
 * @precision high

Copy link
Copy Markdown
Collaborator

@MichaelRFairhurst MichaelRFairhurst left a comment

Choose a reason for hiding this comment

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

Nice! Way to find some high bang-for-the-buck improvements along the way here.

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.

3 participants