Skip to content

Implement Rule 0.2.4, unused functions with limited visibility.#1044

Open
MichaelRFairhurst wants to merge 2 commits intomainfrom
michaelrfairhurst/implement-deadcode-10-rule-0-2-4
Open

Implement Rule 0.2.4, unused functions with limited visibility.#1044
MichaelRFairhurst wants to merge 2 commits intomainfrom
michaelrfairhurst/implement-deadcode-10-rule-0-2-4

Conversation

@MichaelRFairhurst
Copy link
Collaborator

Description

Logic is effectively the same as A0-1-3, though A0-1-3 handled class member linkage incorrectly.

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!)

Copilot AI review requested due to automatic review settings February 18, 2026 20:38
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 MISRA-C++-2023 RULE-0-2-4 (“unused functions with limited visibility”) by factoring the existing AUTOSAR A0-1-3 logic into a shared implementation and extending it to correctly handle class members with internal linkage (e.g., in anonymous namespaces).

Changes:

  • Introduces shared query implementation UnusedLocalFunction and migrates AUTOSAR A0-1-3 to use it.
  • Adds MISRA RULE-0-2-4 wrapper query and a new DeadCode10 rule package/exclusions metadata to host it.
  • Extends unit tests/expected outputs to cover unused public member functions in anonymous namespaces.

Reviewed changes

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

Show a summary per file
File Description
rules.csv Maps RULE-0-2-4 to new DeadCode10 package.
rule_packages/cpp/DeadCode10.json Adds metadata for MISRA RULE-0-2-4 query package.
rule_packages/cpp/DeadCode.json Adds shared_implementation_short_name for A0-1-3 metadata.
cpp/misra/test/rules/RULE-0-2-4/UnusedLimitedVisibilityFunction.testref Wires MISRA test to shared test query.
cpp/misra/src/rules/RULE-0-2-4/UnusedLimitedVisibilityFunction.ql Adds MISRA wrapper query that instantiates shared implementation.
cpp/common/test/rules/unusedlocalfunction/test.cpp Adds C++ test cases for anonymous-namespace class member functions.
cpp/common/test/rules/unusedlocalfunction/UnusedLocalFunction.ql Adds generated test query wrapper for the shared implementation.
cpp/common/test/rules/unusedlocalfunction/UnusedLocalFunction.expected Updates expected results for new test cases.
cpp/common/src/codingstandards/cpp/rules/unusedlocalfunction/UnusedLocalFunction.qll Adds shared implementation, including new anonymous-namespace member handling.
cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll Registers new DeadCode10 package metadata.
cpp/common/src/codingstandards/cpp/exclusions/cpp/DeadCode10.qll Adds autogenerated exclusions/metadata module for DeadCode10.
cpp/autosar/test/rules/A0-1-3/UnusedLocalFunction.testref Wires AUTOSAR test to shared test query.
cpp/autosar/src/rules/A0-1-3/UnusedLocalFunctionOld.ql Adds a copy of the old query implementation.
cpp/autosar/src/rules/A0-1-3/UnusedLocalFunction.ql Refactors AUTOSAR query to instantiate shared implementation.
change_notes/2026-02-18-unused-member-functions-with-internal-linkage.md Adds change note describing the behavior change for A0-1-3.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1 to +10
/**
* @id cpp/autosar/unused-local-function
* @name A0-1-3: Unused local function
* @description Every function defined in an anonymous namespace, or static function with internal
* linkage, or private member function shall be used.
* @kind problem
* @precision very-high
* @problem.severity warning
* @tags external/autosar/id/a0-1-3
* readability
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

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

UnusedLocalFunctionOld.ql is a full query (has @id, @kind, etc.) that duplicates the existing query id cpp/autosar/unused-local-function from UnusedLocalFunction.ql. Because cpp/autosar/src/qlpack.yml doesn't exclude files, this will be included in the pack and can cause duplicate-query-id conflicts / unintended extra shipped query. Remove this file, or convert it into non-query documentation (e.g., move out of the pack, rename to .qll, or remove query metadata) if you need to keep it for reference.

Copilot uses AI. Check for mistakes.
Comment on lines +48 to +50
// Class members in anonymous namespaces also have internal linkage.
this instanceof AnonymousNamespaceFunction and
this instanceof MemberFunction and
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

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

LocalFunction() assigns localFunctionType in multiple disjuncts that can overlap (e.g., a private member function inside an anonymous namespace satisfies both the "Private member" branch and the "Anonymous namespace class member" branch). This can give a single function multiple localFunctionType values and lead to duplicate results with different messages. Make these cases mutually exclusive (for example, exclude private members from the anonymous-namespace-member branch, or restructure with an if/else-style chain) and add/adjust a unit test to guard against duplicated findings.

Suggested change
// Class members in anonymous namespaces also have internal linkage.
this instanceof AnonymousNamespaceFunction and
this instanceof MemberFunction and
// Class members in anonymous namespaces also have internal linkage.
// Exclude private members, which are already covered by the "Private member" case above.
this instanceof AnonymousNamespaceFunction and
this instanceof MemberFunction and
not this.(MemberFunction).isPrivate() and

Copilot uses AI. Check for mistakes.
"correctness"
],
"implementation_scope": {
"description": "Use of any overload of a function in an overload set constitute a use of all members of the set. An overload set is a set of functions with the same name that differ in the number, type and/or qualifiers of their parameters, and, for the purpose of this query, are limited to functions which are declared in the same scope (namespace or class). Functions defined in anonymous (unnamed) namespaces and global namespaces are therefore not currently considered to be part of the same overload set."
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

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

Grammar: the subject is singular (“Use ...”), so "constitute" should be "constitutes" in this sentence.

Copilot uses AI. Check for mistakes.
@MichaelRFairhurst
Copy link
Collaborator Author

MichaelRFairhurst commented Feb 18, 2026

Erroneously added, PR closed and session canceled.

@copilot

Fix format:

/src/debug/protocol/controller.cpp:206:61: error: code should be clang-formatted [-Wclang-format-violations]
engine_->resume(ExecutionRequestKind::CONTINUE);
^
./tests/service/test_protocol.cpp:247:39: error: code should be clang-formatted [-Wclang-format-violations]
Protocol protocol(controller);
^
./tests/service/test_protocol.cpp:250:81: error: code should be clang-formatted [-Wclang-format-violations]
controller.initialize(init_args, [](const InitializeResponseBody &) {});
^
./tests/service/test_protocol.cpp:254:27: error: code should be clang-formatted [-Wclang-format-violations]
args.threadId = 1;
^
./tests/service/test_protocol.cpp:256:61: error: code should be clang-formatted [-Wclang-format-violations]
auto response = controller.continue_execution(args);
^
./tests/service/test_protocol.cpp:279:39: error: code should be clang-formatted [-Wclang-format-violations]
Protocol protocol(controller);
^
./tests/service/test_protocol.cpp:282:81: error: code should be clang-formatted [-Wclang-format-violations]
controller.initialize(init_args, [](const InitializeResponseBody &) {});
^
./tests/service/test_protocol.cpp:286:27: error: code should be clang-formatted [-Wclang-format-violations]
args.threadId = 1;
^
./tests/service/test_protocol.cpp:309:39: error: code should be clang-formatted [-Wclang-format-violations]
Protocol protocol(controller);
^
./tests/service/test_protocol.cpp:312:81: error: code should be clang-formatted [-Wclang-format-violations]
controller.initialize(init_args, [](const InitializeResponseBody &) {});
^
./tests/service/test_protocol.cpp:316:27: error: code should be clang-formatted [-Wclang-format-violations]
args.threadId = 1;
^

Copy link

Copilot AI commented Feb 18, 2026

@MichaelRFairhurst I've opened a new pull request, #1045, to work on those changes. Once the pull request is ready, I'll request review from you.

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

Comments