Skip to content

Conversation

@MichaelRFairhurst
Copy link
Collaborator

Description

Detects use of polymorphic class type expressions as operands to typeid, which may cause unclear evaluation behavior and potential std::bad_typeid exceptions.

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-8-2-9
  • 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!)

Detects use of polymorphic class type expressions as operands to typeid,
which may cause unclear evaluation behavior and potential std::bad_typeid
exceptions.
Copilot AI review requested due to automatic review settings November 22, 2025 01:41
Copilot finished reviewing on behalf of MichaelRFairhurst November 22, 2025 01:44
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 pull request implements RULE-8-2-9 from MISRA C++ 2023, which detects when the typeid operator is used with expressions of polymorphic class type. The rule aims to prevent unclear evaluation behavior, as typeid expressions with polymorphic types are evaluated at runtime (potentially throwing std::bad_typeid), while non-polymorphic types are evaluated at compile-time.

Key changes:

  • Added a new query to detect polymorphic class type expressions used as operands to typeid
  • Created the Preconditions1 rule package for this and future related rules
  • Integrated the new package into the RuleMetadata system

Reviewed changes

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

Show a summary per file
File Description
rules.csv Updated RULE-8-2-9 entry to reference the new Preconditions1 package
rule_packages/cpp/Preconditions1.json New rule package metadata for RULE-8-2-9 with query properties
cpp/misra/src/rules/RULE-8-2-9/PolymorphicClassTypeExpressionInTypeid.ql Main query implementation detecting polymorphic expressions in typeid
cpp/misra/test/rules/RULE-8-2-9/test.cpp Comprehensive test cases covering various scenarios
cpp/misra/test/rules/RULE-8-2-9/PolymorphicClassTypeExpressionInTypeid.qlref Test reference to the query
cpp/misra/test/rules/RULE-8-2-9/PolymorphicClassTypeExpressionInTypeid.expected Expected test results with 6 NON_COMPLIANT findings
cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll Integration of Preconditions1 package into the RuleMetadata system
cpp/common/src/codingstandards/cpp/exclusions/cpp/Preconditions1.qll Auto-generated package file with query metadata and accessor functions

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get 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.

2 participants