Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Implement package exceptions3 for MISRA C++#901

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
MichaelRFairhurst wants to merge3 commits intomain
base:main
Choose a base branch
Loading
frommichaelrfairhurst/implement-package-exceptions3

Conversation

MichaelRFairhurst
Copy link
Contributor

Description

Misra C++ exceptions rules

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-18-3-1
    • RULE-18-3-2
    • RULE-18-4-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 ofshared 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 thestyle 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 thestyle 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!)

Adds support for:- RULE-18-3-1- RULE-18-3-2- RULE-18-4-1
@CopilotCopilotAI review requested due to automatic review settingsMay 20, 2025 17:18
Copy link
Contributor

@CopilotCopilotAI 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 introduces a new “Exceptions3” package for MISRA C++ exception rules, adding three new rules (18-3-1, 18-3-2, 18-4-1) along with tests, query implementations, and metadata updates.

  • Added unit tests (.cpp, .qlref, .expected) covering four variants of rule 18-3-1.
  • Introduced CodeQL queries for RULE-18-3-1 (missing catch-all in main), RULE-18-3-2 (class exceptions caught by value), and RULE-18-4-1 (exception-unfriendly functions must be noexcept).
  • Updated exclusion metadata (RuleMetadata.qll, Exceptions3.qll) and supporting QLL libraries (ExceptionFlow, Function, SpecialFunctionExceptions).

Reviewed Changes

Copilot reviewed 33 out of 33 changed files in this pull request and generated 3 comments.

Show a summary per file
FileDescription
cpp/misra/test/rules/RULE-18-3-1.4/test_except_inside_catch.cppAdd NON-COMPLIANT test wherecout in catch-all may throw
cpp/misra/test/rules/RULE-18-3-1.4/MissingCatchAllExceptionHandlerInMain.qlrefReference the new 18-3-1.4 test for the missing-catch rule
cpp/misra/test/rules/RULE-18-3-1.4/MissingCatchAllExceptionHandlerInMain.expectedAdd expected alert for test_except_inside_catch.cpp
cpp/misra/test/rules/RULE-18-3-1.3/test_except_after_catch.cppAdd NON-COMPLIANT test wheref() after catch may throw
cpp/misra/test/rules/RULE-18-3-1.3/MissingCatchAllExceptionHandlerInMain.qlrefReference the new 18-3-1.3 test for the missing-catch rule
cpp/misra/test/rules/RULE-18-3-1.3/MissingCatchAllExceptionHandlerInMain.expectedAdd expected alert for test_except_after_catch.cpp
cpp/misra/test/rules/RULE-18-3-1.2/test_except_before_catch.cppAdd NON-COMPLIANT test wheref() before catch may throw
cpp/misra/test/rules/RULE-18-3-1.2/MissingCatchAllExceptionHandlerInMain.qlrefReference the new 18-3-1.2 test for the missing-catch rule
cpp/misra/test/rules/RULE-18-3-1.2/MissingCatchAllExceptionHandlerInMain.expectedAdd expected alert for test_except_before_catch.cpp
cpp/misra/test/rules/RULE-18-3-1.1/test_missing.cppAdd NON-COMPLIANT test with no catch-all handler
cpp/misra/test/rules/RULE-18-3-1.1/MissingCatchAllExceptionHandlerInMain.qlrefReference the new 18-3-1.1 test for the missing-catch rule
cpp/misra/test/rules/RULE-18-3-1.1/MissingCatchAllExceptionHandlerInMain.expectedAdd expected alert for test_missing.cpp
cpp/misra/src/rules/RULE-18-4-1/ExceptionUnfriendlyFunctionMustBeNoexcept.qlImplement query for exception-unfriendly functions needing noexcept
cpp/misra/src/rules/RULE-18-3-2/ClassExceptionCaughtByValue.qlImplement query to enforce catching classes by (const) reference
cpp/misra/src/rules/RULE-18-3-1/MissingCatchAllExceptionHandlerInMain.qlImplement catch-all-in-main query with custom predicate
cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qllImport new Exceptions3 package in exclusion metadata
cpp/common/src/codingstandards/cpp/exclusions/cpp/Exceptions3.qllAuto-generate Exceptions3Query type and metadata checks
cpp/common/src/codingstandards/cpp/exceptions/ExceptionFlow.qllAdd helpergetATryStmt to locate enclosing try blocks
cpp/common/src/codingstandards/cpp/exceptions/Function.qllAddUserDeclaredFunction and function-access-like classes
cpp/common/src/codingstandards/cpp/exceptions/SpecialFunctionExceptions.qllExtend special-function exception descriptions and contexts
Comments suppressed due to low confidence (2)

cpp/common/src/codingstandards/cpp/exceptions/SpecialFunctionExceptions.qll:18

  • [nitpick] Remove or consolidate the redundant import ofExceptionFlow, since it’s also imported with a fully-qualified path.
private import ExceptionFlow

cpp/common/src/codingstandards/cpp/exceptions/SpecialFunctionExceptions.qll:107

  • [nitpick] Adjust indentation of the closing brace to align with the opening brace for consistency.
   }

/**
* @id cpp/misra/exception-unfriendly-function-must-be-noexcept
* @name RULE-18-4-1: Exception-unfriendly functions shall be noexcept
* @description Throwing exceptions in constructors, descructors, copy-constructors, move
Copy link
Preview

CopilotAIMay 20, 2025

Choose a reason for hiding this comment

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

Fix typo: change 'descructors' to 'destructors' in the rule description.

Suggested change
* @descriptionThrowingexceptions in constructors,descructors, copy-constructors, move
* @descriptionThrowingexceptions in constructors,destructors, copy-constructors, move

Copilot uses AI. Check for mistakes.

@@ -121,6 +121,11 @@ TryStmt getNearestTry(Stmt s) {
else result = getNearestTry(s.getParent())
}

/** Gets a try statement that contains the given statement. */
TryStmt getATryStmt(Stmt s) {
result.getStmt() = s.getEnclosingStmt().getEnclosingBlock*()
Copy link
Preview

CopilotAIMay 20, 2025

Choose a reason for hiding this comment

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

ThegetATryStmt predicate may match any enclosing block rather than specifically aTryStmt. Consider modeling it aftergetNearestTry to ensure it only returns actualTryStmt nodes.

Suggested change
result.getStmt()=s.getEnclosingStmt().getEnclosingBlock*()
result=s.getEnclosingStmt().getEnclosingBlock*()andresultinstanceof TryStmt

Copilot uses AI. Check for mistakes.

not isExcluded(catch, Exceptions3Package::classExceptionCaughtByValueQuery()) and
type = catch.getParameter().getType() and
type.stripTopLevelSpecifiers() instanceof Class
select catch, "Catch block catches a class type '" + type + "' by value, which can lead to slicing."
Copy link
Preview

CopilotAIMay 20, 2025

Choose a reason for hiding this comment

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

[nitpick] When concatenating thetype in the select message, usetype.toString() ortype.getQualifiedName() to ensure a clear textual representation.

Suggested change
selectcatch,"Catch block catches a class type '"+type+"' by value, which can lead to slicing."
selectcatch,"Catch block catches a class type '"+type.getQualifiedName()+"' by value, which can lead to slicing."

Copilot uses AI. Check for mistakes.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

Copilot code reviewCopilotCopilot left review comments

@lcarteylcarteyAwaiting requested review from lcartey

At least 1 approving review is required to merge this pull request.

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

1 participant
@MichaelRFairhurst

[8]ページ先頭

©2009-2025 Movatter.jp