Skip to content

Narrowly focused implementation of RULE 15-0-1#1121

Open
MichaelRFairhurst wants to merge 15 commits intomainfrom
michaelrfairhurst/classes-3-take-2-rule-15-0-1
Open

Narrowly focused implementation of RULE 15-0-1#1121
MichaelRFairhurst wants to merge 15 commits intomainfrom
michaelrfairhurst/classes-3-take-2-rule-15-0-1

Conversation

@MichaelRFairhurst
Copy link
Copy Markdown
Collaborator

Description

please enter the description of your change here

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 number here
  • 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!)

@MichaelRFairhurst MichaelRFairhurst changed the title First round tests Narrowly focused implementation of RULE 15-0-1 Apr 29, 2026
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-15-0-1 implementation (plus an audit companion query) to detect incorrectly provided special member functions, including packaging/metadata wiring and a dedicated test suite.

Changes:

  • Introduces ImproperlyProvidedSpecialMemberFunctions.ql and ImproperlyProvidedSpecialMemberFunctionsAudit.ql for RULE-15-0-1.
  • Adds helper library logic (AnalyzableClass.qll) to model special-member availability/customization.
  • Registers the new rule package in exclusions/metadata and adds comprehensive .qlref/.expected/C++ test fixtures.
Show a summary per file
File Description
rule_packages/cpp/Classes3.json Adds RULE-15-0-1 rule package entries (main + audit).
cpp/misra/src/rules/RULE-15-0-1/ImproperlyProvidedSpecialMemberFunctions.ql Main RULE-15-0-1 query implementation and message logic.
cpp/misra/src/rules/RULE-15-0-1/ImproperlyProvidedSpecialMemberFunctionsAudit.ql Audit query for “not analyzable” classes.
cpp/misra/src/rules/RULE-15-0-1/AnalyzableClass.qll Shared modeling of special member functions for analyzable classes.
cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll Wires the new Classes3 package into query metadata/exclusions.
cpp/common/src/codingstandards/cpp/exclusions/cpp/Classes3.qll New autogenerated metadata module for the Classes3 package.
cpp/misra/test/rules/RULE-15-0-1/test.cpp New C++ test fixture covering compliant/non-compliant and audit cases.
cpp/misra/test/rules/RULE-15-0-1/*.qlref Test references to the production queries.
cpp/misra/test/rules/RULE-15-0-1/*.expected Expected results for both main and audit queries.

Copilot's findings

Comments suppressed due to low confidence (4)

cpp/misra/test/rules/RULE-15-0-1/test.cpp:376

  • The audit .expected file reports an alert at this class, but the test source does not mark it // NON_COMPLIANT (or similar). Please add the appropriate NON_COMPLIANT annotation here or remove/update the corresponding row in ImproperlyProvidedSpecialMemberFunctionsAudit.expected.
class UnmovableDerivedPublicVirtualDtor
    : public UnmovableBasePublicVirtualDtor {};

cpp/misra/test/rules/RULE-15-0-1/test.cpp:403

  • The audit .expected file reports an alert at this class, but the test source does not mark it // NON_COMPLIANT (or similar). Please add the appropriate NON_COMPLIANT annotation here or remove/update the corresponding row in ImproperlyProvidedSpecialMemberFunctionsAudit.expected.
class ProtectedDtorDerived : public BaseProtectedDtor {};

cpp/misra/test/rules/RULE-15-0-1/test.cpp:416

  • The audit .expected file reports an alert at this class, but the test source does not mark it // NON_COMPLIANT (or similar). Please add the appropriate NON_COMPLIANT annotation here or remove/update the corresponding row in ImproperlyProvidedSpecialMemberFunctionsAudit.expected.
class VirtualProtectedDtorDerived : public BaseVirtualProtectedDtor {};

cpp/misra/test/rules/RULE-15-0-1/test.cpp:390

  • The audit .expected file reports an alert at this class, but the test source does not mark it // NON_COMPLIANT (or similar). Please add the appropriate NON_COMPLIANT annotation here or remove/update the corresponding row in ImproperlyProvidedSpecialMemberFunctionsAudit.expected.
class UnmovablePrivateVirtualDtorDerived : public UnmovablePrivateVirtualDtor {
};
  • Files reviewed: 11/11 changed files
  • Comments generated: 9

Comment on lines +31 to +45
Constructor getMoveConstructor(Class c) {
if
not exists(MoveConstructor mc | mc = c.getAConstructor() and isUserDeclared(mc)) and
implicitMoveIsSuppressed(c)
then result = c.getAConstructor().(CopyConstructor)
else result = c.getAConstructor().(MoveConstructor)
}

Operator getMoveAssign(Class c) {
if
not exists(MoveAssignmentOperator mc | mc = c.getAMemberFunction() and isUserDeclared(mc)) and
implicitMoveIsSuppressed(c)
then result = c.getAMemberFunction().(CopyAssignmentOperator)
else result = c.getAMemberFunction().(MoveAssignmentOperator)
}
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

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

getMoveConstructor and getMoveAssign are public predicates/functions in a library file but have no QLDoc. Either make them private if they are internal helpers, or add QLDoc documenting their behavior and parameters.

Copilot uses AI. Check for mistakes.
Comment on lines +47 to +56
newtype TSpecialMember =
TMoveConstructor() or
TMoveAssignmentOperator() or
TCopyConstructor() or
TCopyAssignmentOperator() or
TDestructor()

class AnalyzableClass extends Class {
CopyConstructor copyCtor;
// The move constructor may be suppressed, and the copy constructor may be used during moves.
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

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

TSpecialMember and AnalyzableClass are public declarations without QLDoc. Repository guidelines require all public types/classes/newtypes in .qll libraries to be documented, or marked private if they are not part of the public API.

Copilot uses AI. Check for mistakes.
DELETED, DELETED, DEFAULTED)
};

class UnmovableNonvirtualDerived : public UnmovableBaseNonvirtualDtor {};
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

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

The audit .expected file reports an alert at this class, but the test source does not mark it // NON_COMPLIANT (or similar). Please add the appropriate NON_COMPLIANT annotation here or remove/update the corresponding row in ImproperlyProvidedSpecialMemberFunctionsAudit.expected.

This issue also appears in the following locations of the same file:

  • line 375
  • line 389
  • line 403
  • line 416

Copilot generated this review using guidance from repository custom instructions.
result = "destructor"
}

string missingKinds(Class c) { result = concat(missingKind(c), " and ") }
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

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

missingKinds uses concat(...), which can yield non-deterministic ordering when multiple kinds are missing, making alert messages (and .expected files) flaky. Consider using strictconcat(...) or otherwise imposing a stable order on the joined kinds.

Suggested change
string missingKinds(Class c) { result = concat(missingKind(c), " and ") }
string missingKinds(Class c) { result = strictconcat(missingKind(c), " and ") }

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +2
import cpp

Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

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

This .qll file is missing a top-level QLDoc header comment. Repository guidelines require library files to start with a documentation comment explaining the purpose of the library.

See below for a potential fix:

@ -1,3 +1,7 @@
/**
 * Provides classes and predicates for identifying analyzable classes and
 * relevant special member functions for MISRA rule `RULE-15-0-1`.
 */

Copilot uses AI. Check for mistakes.
Comment on lines +31 to +37
#define DEFINE_ALL_SPECIAL_MEMBERS(NAME, \
COPY_CTOR_SPEC, MOVE_CTOR_SPEC, COPY_ASSIGN_SPEC, MOVE_ASSIGN_SPEC, DTOR_SPEC) \
COPY_CTOR(NAME) COPY_CTOR_SPEC /* T(const T&) = default; */ \
MOVE_CTOR(NAME) MOVE_CTOR_SPEC /* T(T&&) = default; */ \
COPY_ASSIGN(NAME) COPY_ASSIGN_SPEC /* T& operator=(const T&) = default; */ \
MOVE_ASSIGN(NAME) MOVE_ASSIGN_SPEC /* T& operator=(T&&) = default; */ \
DTOR(NAME) DTOR_SPEC /* ~T() = default; */
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

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

These macro definitions exceed the repository's 100-character line limit for CodeQL test files (see custom-instructions/repo/.github/copilot-instructions.md:79). Please wrap/split the macro parameter list and/or align continuations so each line stays within 100 characters.

Suggested change
#define DEFINE_ALL_SPECIAL_MEMBERS(NAME, \
COPY_CTOR_SPEC, MOVE_CTOR_SPEC, COPY_ASSIGN_SPEC, MOVE_ASSIGN_SPEC, DTOR_SPEC) \
COPY_CTOR(NAME) COPY_CTOR_SPEC /* T(const T&) = default; */ \
MOVE_CTOR(NAME) MOVE_CTOR_SPEC /* T(T&&) = default; */ \
COPY_ASSIGN(NAME) COPY_ASSIGN_SPEC /* T& operator=(const T&) = default; */ \
MOVE_ASSIGN(NAME) MOVE_ASSIGN_SPEC /* T& operator=(T&&) = default; */ \
DTOR(NAME) DTOR_SPEC /* ~T() = default; */
#define DEFINE_ALL_SPECIAL_MEMBERS( \
NAME, COPY_CTOR_SPEC, MOVE_CTOR_SPEC, \
COPY_ASSIGN_SPEC, MOVE_ASSIGN_SPEC, DTOR_SPEC) \
COPY_CTOR(NAME) COPY_CTOR_SPEC /* T(const T&) = default; */ \
MOVE_CTOR(NAME) MOVE_CTOR_SPEC /* T(T&&) = default; */ \
COPY_ASSIGN(NAME) COPY_ASSIGN_SPEC \
/* T& operator=(const T&) = default; */ \
MOVE_ASSIGN(NAME) MOVE_ASSIGN_SPEC \
/* T& operator=(T&&) = default; */ \
DTOR(NAME) DTOR_SPEC /* ~T() = default; */

Copilot uses AI. Check for mistakes.
Comment on lines +48 to +49
"Class '" + c.getName() + "' is not analyzable because the " + kinds +
" are not present in the CodeQL database."
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

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

The message always uses the plural verb "are" ("the X are not present"), which is grammatically incorrect when only one kind is missing (for example, "the destructor"). Adjust the message to use "is" for a single missing kind, or restructure the sentence to avoid number agreement issues.

Suggested change
"Class '" + c.getName() + "' is not analyzable because the " + kinds +
" are not present in the CodeQL database."
"Class '" + c.getName() + "' is not analyzable because the CodeQL database does not " +
"contain the " + kinds + "."

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +7
{
"MISRA-C++-2023": {
"RULE-15-0-1": {
"properties": {
"enforcement": "decidable",
"obligation": "required"
},
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

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

The PR description still contains the unfilled template (placeholders/unchecked checklists), which makes it hard to verify whether a change note is required and what type of change this is. Please update the PR description sections (change type, rule list, and change note confirmation) to reflect this PR.

Copilot uses AI. Check for mistakes.
private predicate implicitMoveIsSuppressed(Class c) {
isUserDeclared(c.getAConstructor().(CopyConstructor))
or
isUserDeclared(c.getAConstructor().(CopyAssignmentOperator))
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

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

implicitMoveIsSuppressed checks c.getAConstructor().(CopyAssignmentOperator), but copy assignment operators are not constructors. This makes the suppression logic incorrect for classes with a user-declared copy assignment operator, which can affect how move operations are modeled. Use c.getAMemberFunction().(CopyAssignmentOperator) (or equivalent) here.

Suggested change
isUserDeclared(c.getAConstructor().(CopyAssignmentOperator))
isUserDeclared(c.getAMemberFunction().(CopyAssignmentOperator))

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.

3 participants