Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion c/common/test/rules/unusedparameter/UnusedParameter.ql
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
// GENERATED FILE - DO NOT MODIFY
import codingstandards.cpp.rules.unusedparameter.UnusedParameter

class TestFileQuery extends UnusedParameterSharedQuery, TestQuery { }
module UnusedParameterTestConfig implements UnusedParameterSharedConfigSig {
Query getQuery() { result instanceof TestQuery }
}

import UnusedParameterShared<UnusedParameterTestConfig>
6 changes: 4 additions & 2 deletions c/misra/src/rules/RULE-2-7/UnusedParameter.ql
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import cpp
import codingstandards.c.misra
import codingstandards.cpp.rules.unusedparameter.UnusedParameter

class UnusedParameterQuery extends UnusedParameterSharedQuery {
UnusedParameterQuery() { this = DeadCodePackage::unusedParameterQuery() }
module UnusedParameterQueryConfig implements UnusedParameterSharedConfigSig {
Query getQuery() { result = DeadCodePackage::unusedParameterQuery() }
}

import UnusedParameterShared<UnusedParameterQueryConfig>
2 changes: 2 additions & 0 deletions change_notes/2026-02-13-refactor-unused-parameter-queries.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- `A0-1-4`, `RULE-2-7` - `UnusedParameter.ql`:
Copy link

Copilot AI Feb 14, 2026

Choose a reason for hiding this comment

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

The change note mentions only A0-1-4 and RULE-2-7, but this PR also adds a new query for RULE-0-2-2. According to the development handbook guidelines for change notes, the change note should list all queries that have been modified or added. Please add RULE-0-2-2 to the list of affected rules in the change note.

Suggested change
- `A0-1-4`, `RULE-2-7` - `UnusedParameter.ql`:
- `A0-1-4`, `RULE-2-7`, `RULE-0-2-2` - `UnusedParameter.ql`:

Copilot uses AI. Check for mistakes.
- Refactored to be able to share most logic between MISRA C, MISRA C++, and AUTOSAR. No visible change in behavior expected.
11 changes: 9 additions & 2 deletions cpp/autosar/src/rules/A0-1-4/UnusedParameter.ql
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ import codingstandards.cpp.autosar
import codingstandards.cpp.deadcode.UnusedParameters
import codingstandards.cpp.rules.unusedparameter.UnusedParameter

class UnusedParameterQuery extends UnusedParameterSharedQuery {
UnusedParameterQuery() { this = DeadCodePackage::unusedParameterQuery() }
module UnusedParameterQueryConfig implements UnusedParameterSharedConfigSig {
Query getQuery() { result = DeadCodePackage::unusedParameterQuery() }

predicate excludeParameter(Parameter p) {
// Virtual functions are covered by a different rule
p.getFunction().isVirtual()
}
}

import UnusedParameterShared<UnusedParameterQueryConfig>
1 change: 1 addition & 0 deletions cpp/autosar/test/rules/A0-1-4/UnusedParameter.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
| test.cpp:2:14:2:14 | x | Unused parameter 'x' for function $@. | test.cpp:2:8:2:8 | b | A::b |
1 change: 1 addition & 0 deletions cpp/autosar/test/rules/A0-1-4/UnusedParameter.qlref
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rules/A0-1-4/UnusedParameter.ql
1 change: 0 additions & 1 deletion cpp/autosar/test/rules/A0-1-4/UnusedParameter.testref

This file was deleted.

7 changes: 7 additions & 0 deletions cpp/autosar/test/rules/A0-1-4/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class A {
void b(int x) {} // NON_COMPLIANT

// This is specially excluded from A0-1-4, covered by a different rule,
// even though it's non compliant in the shared query.
virtual void d(int x, int y) {} // COMPLIANT
};
26 changes: 26 additions & 0 deletions cpp/common/src/codingstandards/cpp/exclusions/cpp/DeadCode8.qll
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//** THIS FILE IS AUTOGENERATED, DO NOT MODIFY DIRECTLY. **/
import cpp
import RuleMetadata
import codingstandards.cpp.exclusions.RuleMetadata

newtype DeadCode8Query = TUnusedParameterMisraCppQuery()

predicate isDeadCode8QueryMetadata(Query query, string queryId, string ruleId, string category) {
query =
// `Query` instance for the `unusedParameterMisraCpp` query
DeadCode8Package::unusedParameterMisraCppQuery() and
queryId =
// `@id` for the `unusedParameterMisraCpp` query
"cpp/misra/unused-parameter-misra-cpp" and
ruleId = "RULE-0-2-2" and
category = "required"
}

module DeadCode8Package {
Query unusedParameterMisraCppQuery() {
//autogenerate `Query` type
result =
// `Query` type for `unusedParameterMisraCpp` query
TQueryCPP(TDeadCode8PackageQuery(TUnusedParameterMisraCppQuery()))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Conversions2
import DeadCode
import DeadCode3
import DeadCode4
import DeadCode8
import Declarations
import ExceptionSafety
import Exceptions1
Expand Down Expand Up @@ -91,6 +92,7 @@ newtype TCPPQuery =
TDeadCodePackageQuery(DeadCodeQuery q) or
TDeadCode3PackageQuery(DeadCode3Query q) or
TDeadCode4PackageQuery(DeadCode4Query q) or
TDeadCode8PackageQuery(DeadCode8Query q) or
TDeclarationsPackageQuery(DeclarationsQuery q) or
TExceptionSafetyPackageQuery(ExceptionSafetyQuery q) or
TExceptions1PackageQuery(Exceptions1Query q) or
Expand Down Expand Up @@ -163,6 +165,7 @@ predicate isQueryMetadata(Query query, string queryId, string ruleId, string cat
isDeadCodeQueryMetadata(query, queryId, ruleId, category) or
isDeadCode3QueryMetadata(query, queryId, ruleId, category) or
isDeadCode4QueryMetadata(query, queryId, ruleId, category) or
isDeadCode8QueryMetadata(query, queryId, ruleId, category) or
isDeclarationsQueryMetadata(query, queryId, ruleId, category) or
isExceptionSafetyQueryMetadata(query, queryId, ruleId, category) or
isExceptions1QueryMetadata(query, queryId, ruleId, category) or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import codingstandards.cpp.Customizations
import codingstandards.cpp.Exclusions
import codingstandards.cpp.deadcode.UnusedParameters

abstract class UnusedParameterSharedQuery extends Query { }
signature module UnusedParameterSharedConfigSig {
Query getQuery();

Query getQuery() { result instanceof UnusedParameterSharedQuery }
default predicate excludeParameter(Parameter p) { none() }
}

predicate isMaybeUnusedParameter(Parameter parameter) {
parameter.getAnAttribute().toString() = "maybe_unused"
Expand All @@ -19,12 +21,13 @@ predicate isLambdaParameter(Parameter parameter) {
exists(LambdaExpression lambda | lambda.getLambdaFunction().getParameter(_) = parameter)
}

query predicate problems(UnusedParameter p, string message, Function f, string fName) {
not isExcluded(p, getQuery()) and
not isMaybeUnusedParameter(p) and
(if isLambdaParameter(p) then fName = "lambda expression" else fName = f.getQualifiedName()) and
f = p.getFunction() and
// Virtual functions are covered by a different rule
not f.isVirtual() and
message = "Unused parameter '" + p.getName() + "' for function $@."
module UnusedParameterShared<UnusedParameterSharedConfigSig Config> {
query predicate problems(UnusedParameter p, string message, Function f, string fName) {
not isExcluded(p, Config::getQuery()) and
not isMaybeUnusedParameter(p) and
not Config::excludeParameter(p) and
(if isLambdaParameter(p) then fName = "lambda expression" else fName = f.getQualifiedName()) and
f = p.getFunction() and
message = "Unused parameter '" + p.getName() + "' for function $@."
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
| test.cpp:8:22:8:22 | x | Unused parameter 'x' for function $@. | test.cpp:8:6:8:16 | test_unused | test_unused |
| test.cpp:16:14:16:14 | x | Unused parameter 'x' for function $@. | test.cpp:16:8:16:8 | b | A::b |
| test.cpp:35:14:35:14 | y | Unused parameter 'y' for function $@. | test.cpp:34:9:34:9 | operator() | lambda expression |
| test.cpp:21:22:21:22 | x | Unused parameter 'x' for function $@. | test.cpp:21:16:21:16 | d | A::d |
| test.cpp:21:29:21:29 | y | Unused parameter 'y' for function $@. | test.cpp:21:16:21:16 | d | A::d |
| test.cpp:38:14:38:14 | y | Unused parameter 'y' for function $@. | test.cpp:37:9:37:9 | operator() | lambda expression |
6 changes: 5 additions & 1 deletion cpp/common/test/rules/unusedparameter/UnusedParameter.ql
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
// GENERATED FILE - DO NOT MODIFY
import codingstandards.cpp.rules.unusedparameter.UnusedParameter

class TestFileQuery extends UnusedParameterSharedQuery, TestQuery { }
module UnusedParameterTestConfig implements UnusedParameterSharedConfigSig {
Query getQuery() { result instanceof TestQuery }
}

import UnusedParameterShared<UnusedParameterTestConfig>
11 changes: 7 additions & 4 deletions cpp/common/test/rules/unusedparameter/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ void test_unnamed(
}

class A {
int a(int x) { return x; } // COMPLIANT
void b(int x) {} // NON_COMPLIANT
void c(int) {} // COMPLIANT
virtual void d(int x, int y) {} // virtual, not covered by this rule
int a(int x) { return x; } // COMPLIANT
void b(int x) {} // NON_COMPLIANT
void c(int) {} // COMPLIANT

// This is a violation of A0-1-4, but not a violation of Rule 0-0-2, so it's
Copy link

Copilot AI Feb 14, 2026

Choose a reason for hiding this comment

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

The comment says "Rule 0-0-2" but should be "RULE-0-2-2" to match the standard naming convention used elsewhere in the codebase.

Suggested change
// This is a violation of A0-1-4, but not a violation of Rule 0-0-2, so it's
// This is a violation of A0-1-4, but not a violation of RULE-0-2-2, so it's

Copilot uses AI. Check for mistakes.
// accepted by the default shared logic. See A0-1-4 tests for coverage.
virtual void d(int x, int y) {} // COMPLIANT
};

void f(
Expand Down
29 changes: 29 additions & 0 deletions cpp/misra/src/rules/RULE-0-2-2/UnusedParameterMisraCpp.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* @id cpp/misra/unused-parameter-misra-cpp
* @name RULE-0-2-2: There shall be no unused named parameters in non-virtual functions
Copy link

Copilot AI Feb 14, 2026

Choose a reason for hiding this comment

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

According to rules.csv line 831, RULE-0-2-2 maps to both A0-1-4 (non-virtual functions) and A0-1-5 (virtual functions), indicating it should apply to all named function parameters. The query name incorrectly states "non-virtual functions" when it should apply to all functions. The name should be updated to remove the "non-virtual" restriction, for example: "There shall be no unused named parameters in functions".

Suggested change
* @name RULE-0-2-2: There shall be no unused named parameters in non-virtual functions
* @name RULE-0-2-2: There shall be no unused named parameters in functions

Copilot uses AI. Check for mistakes.
* @description Unused parameters can indicate a mistake when implementing the function.
* @kind problem
* @precision very-high
* @problem.severity warning
* @tags external/misra/id/rule-0-2-2
* scope/single-translation-unit
* readability
* maintainability
* external/misra/enforcement/decidable
* external/misra/obligation/required
*/

import cpp
import codingstandards.cpp.misra as Misra
import codingstandards.cpp.rules.unusedparameter.UnusedParameter

module UnusedParameterQueryConfig implements UnusedParameterSharedConfigSig {
Query getQuery() { result = Misra::DeadCode8Package::unusedParameterMisraCppQuery() }

predicate excludeParameter(Parameter p) {
// Exclude parameters which are unnamed in the definition.
not exists(p.getFunction().getDefinition().getParameterDeclarationEntry(p.getIndex()).getName())
}
}

import UnusedParameterShared<UnusedParameterQueryConfig>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
| test.cpp:1:13:1:13 | x | Unused parameter 'x' for function $@. | test.cpp:1:6:1:7 | f0 | f0 |
| test.cpp:9:13:9:13 | x | Unused parameter 'x' for function $@. | test.cpp:9:6:9:7 | f4 | f4 |
| test.cpp:18:13:18:13 | y | Unused parameter 'y' for function $@. | test.cpp:18:6:18:7 | f7 | f7 |
| test.cpp:21:13:21:13 | y | Unused parameter 'y' for function $@. | test.cpp:21:6:21:7 | f8 | f8 |
| test.cpp:24:23:24:23 | x | Unused parameter 'x' for function $@. | test.cpp:24:16:24:17 | m0 | C1::m0 |
| test.cpp:36:15:36:15 | x | Unused parameter 'x' for function $@. | test.cpp:36:8:36:9 | m0 | C3::m0 |
| test.cpp:37:15:37:15 | x | Unused parameter 'x' for function $@. | test.cpp:37:8:37:9 | m1 | C3::m1 |
| test.cpp:38:15:38:15 | x | Unused parameter 'x' for function $@. | test.cpp:38:8:38:9 | m2 | C3::m2 |
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rules/RULE-0-2-2/UnusedParameterMisraCpp.ql
45 changes: 45 additions & 0 deletions cpp/misra/test/rules/RULE-0-2-2/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
void f0(int x) {} // NON_COMPLIANT
void f1(int x) { x; } // COMPLIANT
void f2(int) {} // COMPLIANT

void f3(int);
void f3(int) {} // COMPLIANT

void f4(int);
void f4(int x) {} // NON_COMPLIANT

void f5(int);
void f5(int x) { x; } // COMPLIANT

void f6(int x);
void f6(int) {} // COMPLIANT

void f7(int x);
void f7(int y) {} // NON_COMPLIANT

void f8(int i);
void f8(int y) {} // NON_COMPLIANT

class C1 {
virtual void m0(int x) {} // NON_COMPLIANT
virtual void m1(int) {} // COMPLIANT
virtual void m2([[maybe_unused]] int x) {} // COMPLIANT
};

class C2 : C1 {
void m0(int) override {} // COMPLIANT
void m1(int) override {} // COMPLIANT
void m2(int) override {} // COMPLIANT
};

class C3 : C1 {
void m0(int x) override {} // NON_COMPLIANT
void m1(int x) override {} // NON_COMPLIANT
void m2(int x) override {} // NON_COMPLIANT
};

class C4 : C1 {
void m0([[maybe_unused]] int x) override {} // COMPLIANT
void m1([[maybe_unused]] int x) override {} // COMPLIANT
void m2([[maybe_unused]] int x) override {} // COMPLIANT
};
27 changes: 27 additions & 0 deletions rule_packages/cpp/DeadCode8.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"MISRA-C++-2023": {
"RULE-0-2-2": {
"properties": {
"enforcement": "decidable",
"obligation": "required"
},
"queries": [
{
"description": "Unused parameters can indicate a mistake when implementing the function.",
"kind": "problem",
"name": "There shall be no unused named parameters in non-virtual functions",
Copy link

Copilot AI Feb 14, 2026

Choose a reason for hiding this comment

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

According to rules.csv line 831, RULE-0-2-2 maps to both A0-1-4 (non-virtual functions) and A0-1-5 (virtual functions), meaning it should apply to all named function parameters. The query name incorrectly restricts this to "non-virtual functions". Update the name to reflect the actual scope, for example: "There shall be no unused named parameters in functions".

This issue also appears on line 24 of the same file.

Copilot uses AI. Check for mistakes.
"precision": "very-high",
"severity": "warning",
"short_name": "UnusedParameterMisraCpp",
"tags": [
"scope/single-translation-unit",
"readability",
"maintainability"
],
"shared_implementation_short_name": "UnusedParameter"
}
],
"title": "There shall be no unused named parameters in non-virtual functions."
}
}
}
2 changes: 1 addition & 1 deletion rules.csv
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ cpp,MISRA-C++-2023,RULE-0-0-2,Yes,Advisory,Undecidable,System,Controlling expres
cpp,MISRA-C++-2023,RULE-0-1-1,Yes,Advisory,Undecidable,System,A value should not be unnecessarily written to a local object,A0-1-1,DeadCode2,Medium,
cpp,MISRA-C++-2023,RULE-0-1-2,Yes,Required,Decidable,Single Translation Unit,The value returned by a function shall be used,A0-1-2,DeadCode2,Easy,
cpp,MISRA-C++-2023,RULE-0-2-1,Yes,Advisory,Decidable,Single Translation Unit,Variables with limited visibility should be used at least once,M0-1-3,DeadCode2,Easy,
cpp,MISRA-C++-2023,RULE-0-2-2,Yes,Required,Decidable,Single Translation Unit,A named function parameter shall be used at least once,"A0-1-4, A0-1-5",DeadCode2,Easy,
cpp,MISRA-C++-2023,RULE-0-2-2,Yes,Required,Decidable,Single Translation Unit,A named function parameter shall be used at least once,"A0-1-4, A0-1-5",DeadCode8,Easy,
cpp,MISRA-C++-2023,RULE-0-2-3,Yes,Advisory,Decidable,Single Translation Unit,Types with limited visibility should be used at least once,A0-1-6,DeadCode2,Easy,
cpp,MISRA-C++-2023,RULE-0-2-4,Yes,Advisory,Decidable,System,Functions with limited visibility should be used at least once,A0-1-3,DeadCode2,Easy,
cpp,MISRA-C++-2023,DIR-0-3-1,Yes,Advisory,,,Floating-point arithmetic should be used appropriately,,FloatingPoint,Hard,
Expand Down
Loading