Skip to content

Add Banned2, Banned3, and Banned4#1080

Open
jeongsoolee09 wants to merge 22 commits intomainfrom
jeongsoolee09/MISRA-C++-2023-Banned234
Open

Add Banned2, Banned3, and Banned4#1080
jeongsoolee09 wants to merge 22 commits intomainfrom
jeongsoolee09/MISRA-C++-2023-Banned234

Conversation

@jeongsoolee09
Copy link
Collaborator

@jeongsoolee09 jeongsoolee09 commented Mar 13, 2026

Description

Add package Banned2, Banned3, and Banned4, which are RULE-10-2-2, RULE-10-2-3, and RULE-10-3-1 respectively.

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-2-2
    • RULE-10-2-3
    • RULE-10-3-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!)

@jeongsoolee09 jeongsoolee09 marked this pull request as ready for review March 22, 2026 00:46
Copilot AI review requested due to automatic review settings March 22, 2026 00:46
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 three new MISRA C++ 2023 “Banned*” rule packages and their CodeQL implementations/tests, then wires them into the C++ exclusions/metadata and rules.csv mapping.

Changes:

  • Add new rule packages Banned2, Banned3, Banned4 and map RULE-10-2-2/10-2-3/10-3-1 to them in rules.csv.
  • Add new CodeQL queries implementing the three MISRA rules and corresponding unit tests (.qlref + .expected).
  • Integrate the new packages into C++ exclusions metadata (RuleMetadata.qll + autogenerated Banned{2,3,4}.qll).

Reviewed changes

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

Show a summary per file
File Description
rules.csv Re-points three MISRA C++ rules from Banned to Banned2/3/4.
rule_packages/cpp/Banned2.json Adds package metadata for RULE-10-2-2 query.
rule_packages/cpp/Banned3.json Adds package metadata for RULE-10-2-3 query.
rule_packages/cpp/Banned4.json Adds package metadata for RULE-10-3-1 query.
cpp/misra/src/rules/RULE-10-2-2/UnscopedEnumerationsShouldNotBeDeclared.ql New query for unscoped enums outside class/struct scope.
cpp/misra/src/rules/RULE-10-2-3/UnscopedEnumWithoutFixedUnderlyingTypeUsed.ql New query for uses of unfixed unscoped enums in numeric contexts.
cpp/misra/src/rules/RULE-10-3-1/UnnamedNamespacesInHeaderFiles.ql New query detecting anonymous namespaces in header files.
cpp/misra/test/rules/RULE-10-2-2/test.cpp Test cases for RULE-10-2-2.
cpp/misra/test/rules/RULE-10-2-2/UnscopedEnumerationsShouldNotBeDeclared.qlref Test wiring to production query.
cpp/misra/test/rules/RULE-10-2-2/UnscopedEnumerationsShouldNotBeDeclared.expected Expected results for RULE-10-2-2 tests.
cpp/misra/test/rules/RULE-10-2-3/test.cpp Test cases for RULE-10-2-3.
cpp/misra/test/rules/RULE-10-2-3/UnscopedEnumWithoutFixedUnderlyingTypeUsed.qlref Test wiring to production query.
cpp/misra/test/rules/RULE-10-2-3/UnscopedEnumWithoutFixedUnderlyingTypeUsed.expected Expected results for RULE-10-2-3 tests.
cpp/misra/test/rules/RULE-10-3-1/test.hpp Header fixture containing compliant/non-compliant namespace patterns.
cpp/misra/test/rules/RULE-10-3-1/test1.cpp TU fixture for header anonymous-namespace behavior.
cpp/misra/test/rules/RULE-10-3-1/test2.cpp TU fixture + main for RULE-10-3-1 test setup.
cpp/misra/test/rules/RULE-10-3-1/UnnamedNamespacesInHeaderFiles.qlref Test wiring to production query.
cpp/misra/test/rules/RULE-10-3-1/UnnamedNamespacesInHeaderFiles.expected Expected results for RULE-10-3-1 tests.
cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll Registers new packages in C++ exclusions metadata wiring.
cpp/common/src/codingstandards/cpp/exclusions/cpp/Banned2.qll Autogenerated exclusion package module for Banned2.
cpp/common/src/codingstandards/cpp/exclusions/cpp/Banned3.qll Autogenerated exclusion package module for Banned3.
cpp/common/src/codingstandards/cpp/exclusions/cpp/Banned4.qll Autogenerated exclusion package module for Banned4.

@jeongsoolee09 jeongsoolee09 self-assigned this Mar 23, 2026
Copy link
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.

Only some comments about static alert, and tags, otherwise LGTM!


newtype Banned2Query = TUnscopedEnumerationsShouldNotBeDeclaredQuery()

predicate isBanned2QueryMetadata(Query query, string queryId, string ruleId, string category) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just FYI, we don't need to split rules into their own packages unless they're being split into different PRs. In this case, these can all be part of Banned2.

Also, in this case, three PRs would likely be preferable over one, since the three rules don't have any shared imports in common/ or updates to test/includes/, etc. It is especially valuable to separate 10-2-2, 10-3-1, which are quick to review and approve, from 10-2-3 which has over 200LOC and might take a few back-and-forths to land.

Even the small queries, such as 10-2-2 and 10-3-1, are probably easier to review in isolation going forward because they often a lot of test code each. All in all, one review of 1300loc is harder to find time for than three reviews of ~430loc each, and will take longer to land.

No action required in this case, but to keep in mind going forward 👍

* types.
* @kind problem
* @precision very-high
* @problem.severity error
Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably should be a warning, and either include maintainability or readability tags.

where
not isExcluded(enum, Banned2Package::unscopedEnumerationsShouldNotBeDeclaredQuery()) and
not (enum instanceof ScopedEnum or enum instanceof NestedUnscopedEnum)
select enum, "This enumeration is an unscoped enum not enclosed in a class or a struct."
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's include the enum name here, e.g. "Enum " + enum.getName() + " is an unscoped ..., though we'll maybe want to treat anonymous enums specially.

Generally speaking, we want to avoid constant alert messages.

#include "test.hpp"

/*
* This file demonstrates that anonymous namespace variables
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just FYI, our existing tests don't generally do this kind of demonstration/documentation. Usually we leave the MISRA document to justify itself, and our test cases are purely there to produce alerts (or not). I think the main exception that comes to mind, is that sometimes we will intentionally decide to implement a rule a little differently than described in the standard, and in this case we're more likely to add these kind of demonstrative "test" cases.

* ``` C++
* static_cast<int>(u) == static_cast<int>(s); // COMPLIANT: comparing ints
* ```
* ^^^ To solve this, we use `getExplicitlyConverted`:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice! Yes. Conversions are annoying and this is exactly the correct approach 👍 👍 👍

(I didn't know getExplicitlyConverted existed for a good while when I started..!!!)

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