Skip to content

Michaelrfairhurst/classes4 initialize all fields#1090

Merged
MichaelRFairhurst merged 12 commits intomainfrom
michaelrfairhurst/classes3-initialize-all-fields
Mar 27, 2026
Merged

Michaelrfairhurst/classes4 initialize all fields#1090
MichaelRFairhurst merged 12 commits intomainfrom
michaelrfairhurst/classes3-initialize-all-fields

Conversation

@MichaelRFairhurst
Copy link
Collaborator

@MichaelRFairhurst MichaelRFairhurst commented Mar 19, 2026

Description

Implement 15-1-4

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-15-1-4
  • 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 March 19, 2026 18:22
Copy link
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 initial CodeQL support for MISRA C++:2023 RULE-15-1-4 (“All direct, non-static data members of a class should be initialized before the class object is accessible”) by introducing a new query, wiring it into the rule-package metadata/exclusions, and adding unit tests + expected results.

Changes:

  • Add the NonStaticMemberNotInitBeforeUse query for RULE-15-1-4 and map the rule to a new Classes4 package.
  • Add unit tests for constructors, aggregates, new/new[], and inheriting-constructor using declarations (plus expected results).
  • Register the new package in the exclusions metadata (RuleMetadata.qll) and add the autogenerated Classes4 exclusions module.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
rules.csv Remaps RULE-15-1-4 from Classes3 to new Classes4 package.
rule_packages/cpp/Classes4.json Adds rule-package metadata for RULE-15-1-4 query configuration.
cpp/misra/src/rules/RULE-15-1-4/NonStaticMemberNotInitBeforeUse.ql Implements the new MISRA rule query.
cpp/misra/test/rules/RULE-15-1-4/test.cpp Adds test cases covering compliant/non-compliant initialization scenarios.
cpp/misra/test/rules/RULE-15-1-4/NonStaticMemberNotInitBeforeUse.qlref Points the test harness at the production query.
cpp/misra/test/rules/RULE-15-1-4/NonStaticMemberNotInitBeforeUse.expected Captures expected alerts for the new test cases.
cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll Registers Classes4 package metadata in the C++ exclusions index.
cpp/common/src/codingstandards/cpp/exclusions/cpp/Classes4.qll Adds autogenerated exclusions metadata module for the new package/query.

Copy link
Collaborator

@mbaluda mbaluda left a comment

Choose a reason for hiding this comment

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

LGTM!
Just a note on QLDocs: for classes that select AST elements, especially when using language-specific terminology, it's useful for the QLDoc to refer to actual code
e.g. type.Class and also ref: qldoc-for-classes

I left an example as comment

MichaelRFairhurst and others added 3 commits March 24, 2026 19:36
Co-authored-by: Mauro Baluda <mbaluda@github.com>
Removed redundant comment about aggregate validation at construction time.
Copy link
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 query implementation for RULE-15-1-4 (“initialize all direct, non-static data members before the object is accessible”), wiring it into the rule package/exclusions metadata and providing unit tests.

Changes:

  • Register RULE-15-1-4 under the Classes4 package and add the corresponding rule package JSON metadata.
  • Add the new CodeQL query NonStaticMemberNotInitBeforeUse.ql implementing the rule, including exclusions integration.
  • Add a dedicated test suite (test.cpp, .qlref, .expected) covering constructors, delegating ctors, using-inherited ctors, and aggregate initialization cases.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
rules.csv Re-points RULE-15-1-4 to the new Classes4 package.
rule_packages/cpp/Classes4.json Adds rule package metadata and query registration for RULE-15-1-4.
cpp/misra/src/rules/RULE-15-1-4/NonStaticMemberNotInitBeforeUse.ql Implements the new rule query logic and reporting.
cpp/misra/test/rules/RULE-15-1-4/test.cpp Adds unit tests for compliant/non-compliant initialization patterns.
cpp/misra/test/rules/RULE-15-1-4/NonStaticMemberNotInitBeforeUse.qlref Hooks the test to the production query.
cpp/misra/test/rules/RULE-15-1-4/NonStaticMemberNotInitBeforeUse.expected Adds expected results for the new tests.
cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll Registers the new Classes4 package in exclusions metadata.
cpp/common/src/codingstandards/cpp/exclusions/cpp/Classes4.qll Adds the autogenerated Classes4 exclusions metadata module.
Comments suppressed due to low confidence (2)

cpp/misra/src/rules/RULE-15-1-4/NonStaticMemberNotInitBeforeUse.ql:167

  • The comment above typeContainsAggregate is inaccurate: declarations like Agg x; or const Agg x; are not “initialized by value” unless they use {}/() or have static storage duration. Since this predicate is used to identify when to apply aggregate-initialization checks, consider rephrasing the comment to avoid describing C++ initialization semantics incorrectly.
/**
 * Handles the scenarios where an aggregate may be initialized by value based on a type.
 *
 * For instance, `const Agg`, `Agg[]`, and `Agg[][]` will be initialized by value, but `Agg*` and
 * `Agg&` will not. This is important to verify that aggregates are properly initialized
 */

cpp/misra/src/rules/RULE-15-1-4/NonStaticMemberNotInitBeforeUse.ql:106

  • The doc comment for IncompleteConstructor is internally inconsistent: it says “Non-aggregate class constructors must either belong to an aggregate class…”, but IncompleteConstructor explicitly excludes aggregate classes. Consider rewording the comment to describe the intended allowed cases (e.g. constructors are OK if the declaring type is aggregate OR (for non-aggregate types) they delegate/initialize/etc.).
 * A constructor that does not initialize a field that requires initialization.
 *
 * Non-aggregate class constructors must either:
 * - belong to an aggregate class, or
 * - delegate to another constructor in the same class, or
 * - initialize all fields that require initialization, or
 * - be a defaulted move/copy constructor (which we assume satisfies the above)
 *
 * Constructors that don't meet these criteria are non-compliant.

mbaluda and others added 3 commits March 26, 2026 17:51
@MichaelRFairhurst MichaelRFairhurst added this pull request to the merge queue Mar 26, 2026
Merged via the queue into main with commit f64a352 Mar 27, 2026
25 checks passed
@MichaelRFairhurst MichaelRFairhurst deleted the michaelrfairhurst/classes3-initialize-all-fields branch March 27, 2026 00:57
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