From b9d8b1ec89ac142f71026ee5bb6f5ed6c1825156 Mon Sep 17 00:00:00 2001 From: Mike Fairhurst Date: Tue, 10 Feb 2026 21:09:59 -0800 Subject: [PATCH 1/7] Implement DeadCode6, RULE-0-1-2, shared with A0-1-2. Uses new shared library format templates. --- .../2026-02-10-share-autosar-0-1-2.md | 3 ++ .../src/rules/A0-1-2/UnusedReturnValue.ql | 50 ------------------- .../rules/A0-1-2/UnusedReturnValueAutosar.ql | 27 ++++++++++ .../rules/A0-1-2/UnusedReturnValue.expected | 1 - .../test/rules/A0-1-2/UnusedReturnValue.qlref | 1 - .../A0-1-2/UnusedReturnValueAutosar.testref | 1 + .../cpp/exclusions/cpp/DeadCode.qll | 16 +++--- .../cpp/exclusions/cpp/DeadCode6.qll | 26 ++++++++++ .../cpp/exclusions/cpp/RuleMetadata.qll | 3 ++ .../unusedreturnvalue/UnusedReturnValue.qll | 47 +++++++++++++++++ .../UnusedReturnValue.expected | 1 + .../unusedreturnvalue/UnusedReturnValue.ql | 8 +++ .../test/rules/unusedreturnvalue}/test.cpp | 4 ++ .../RULE-0-1-2/UnusedReturnValueMisraCpp.ql | 25 ++++++++++ .../UnusedReturnValueMisraCpp.testref | 1 + rule_packages/cpp/DeadCode.json | 3 +- rule_packages/cpp/DeadCode6.json | 26 ++++++++++ rules.csv | 2 +- 18 files changed, 183 insertions(+), 62 deletions(-) create mode 100644 change_notes/2026-02-10-share-autosar-0-1-2.md delete mode 100644 cpp/autosar/src/rules/A0-1-2/UnusedReturnValue.ql create mode 100644 cpp/autosar/src/rules/A0-1-2/UnusedReturnValueAutosar.ql delete mode 100644 cpp/autosar/test/rules/A0-1-2/UnusedReturnValue.expected delete mode 100644 cpp/autosar/test/rules/A0-1-2/UnusedReturnValue.qlref create mode 100644 cpp/autosar/test/rules/A0-1-2/UnusedReturnValueAutosar.testref create mode 100644 cpp/common/src/codingstandards/cpp/exclusions/cpp/DeadCode6.qll create mode 100644 cpp/common/src/codingstandards/cpp/rules/unusedreturnvalue/UnusedReturnValue.qll create mode 100644 cpp/common/test/rules/unusedreturnvalue/UnusedReturnValue.expected create mode 100644 cpp/common/test/rules/unusedreturnvalue/UnusedReturnValue.ql rename cpp/{autosar/test/rules/A0-1-2 => common/test/rules/unusedreturnvalue}/test.cpp (86%) create mode 100644 cpp/misra/src/rules/RULE-0-1-2/UnusedReturnValueMisraCpp.ql create mode 100644 cpp/misra/test/rules/RULE-0-1-2/UnusedReturnValueMisraCpp.testref create mode 100644 rule_packages/cpp/DeadCode6.json diff --git a/change_notes/2026-02-10-share-autosar-0-1-2.md b/change_notes/2026-02-10-share-autosar-0-1-2.md new file mode 100644 index 0000000000..5785ed6502 --- /dev/null +++ b/change_notes/2026-02-10-share-autosar-0-1-2.md @@ -0,0 +1,3 @@ + - `A0-1-2` - `UnusedReturnValue.ql`: + - Rule implementation has refactored into a shared library for usage in MISRA C++ ruleset. + - Query file renamed to `UnusedReturnValueAutosar.ql` to distinguish from the MISRA C++ version of the rule. \ No newline at end of file diff --git a/cpp/autosar/src/rules/A0-1-2/UnusedReturnValue.ql b/cpp/autosar/src/rules/A0-1-2/UnusedReturnValue.ql deleted file mode 100644 index 891a44ed2a..0000000000 --- a/cpp/autosar/src/rules/A0-1-2/UnusedReturnValue.ql +++ /dev/null @@ -1,50 +0,0 @@ -/** - * @id cpp/autosar/unused-return-value - * @name A0-1-2: Unused return value - * @description The value returned by a function having a non-void return type that is not an - * overloaded operator shall be used. - * @kind problem - * @precision very-high - * @problem.severity warning - * @tags external/autosar/id/a0-1-2 - * readability - * maintainability - * external/autosar/allocated-target/implementation - * external/autosar/enforcement/automated - * external/autosar/obligation/required - */ - -import cpp -import codingstandards.cpp.autosar -import codingstandards.cpp.Operator -import cpp - -/* - * This query performs a simple syntactic check to ensure that the return value of the function is - * not completely ignored. This matches the examples given in the rule, although the text itself is - * not entirely clear. This means it will not find cases where something is done with the return - * value, but it is not meaningfully read. For example: `int ret_val = f();`, with no subsequent - * access of `ret_val`. However, such a case _would_ be flagged by A0-1-1 - Useless assignment. - */ - -from FunctionCall fc, Function f -where - not isExcluded(fc, DeadCodePackage::unusedReturnValueQuery()) and - // Find function calls in `ExprStmt`s, which indicate the return value is ignored - fc.getParent() instanceof ExprStmt and - // Ignore calls to void functions, which don't return values - not fc.getUnderlyingType() instanceof VoidType and - // Get the function target - f = fc.getTarget() and - // Overloaded (i.e. user defined) operators should behave in the same way as built-in operators, - // so the rule does not require the use of the return value - not f instanceof Operator and - // Exclude cases where the function call is generated within a macro, as the user of the macro is - // not necessarily able to address those results - not fc.isAffectedByMacro() and - // Rule allows disabling this rule where a static_cast or a C-style cast to void is applied - not exists(Cast cast | cast instanceof StaticCast or cast instanceof CStyleCast | - fc.getExplicitlyConverted() = cast and - cast.getActualType() instanceof VoidType - ) -select fc, "Return value from call to $@ is unused.", f, f.getName() diff --git a/cpp/autosar/src/rules/A0-1-2/UnusedReturnValueAutosar.ql b/cpp/autosar/src/rules/A0-1-2/UnusedReturnValueAutosar.ql new file mode 100644 index 0000000000..c6175aa001 --- /dev/null +++ b/cpp/autosar/src/rules/A0-1-2/UnusedReturnValueAutosar.ql @@ -0,0 +1,27 @@ +/** + * @id cpp/autosar/unused-return-value-autosar + * @name A0-1-2: Unused return value + * @description The value returned by a function having a non-void return type that is not an + * overloaded operator shall be used. + * @kind problem + * @precision very-high + * @problem.severity warning + * @tags external/autosar/id/a0-1-2 + * readability + * maintainability + * external/autosar/allocated-target/implementation + * external/autosar/enforcement/automated + * external/autosar/obligation/required + */ + +import cpp +import codingstandards.cpp.autosar +import codingstandards.cpp.rules.unusedreturnvalue.UnusedReturnValue + +module UnusedReturnValueAutosarConfig implements UnusedReturnValueConfigSig { + Query getQuery() { + result = DeadCodePackage::unusedReturnValueAutosarQuery() + } +} + +import UnusedReturnValue diff --git a/cpp/autosar/test/rules/A0-1-2/UnusedReturnValue.expected b/cpp/autosar/test/rules/A0-1-2/UnusedReturnValue.expected deleted file mode 100644 index 480b6d75a3..0000000000 --- a/cpp/autosar/test/rules/A0-1-2/UnusedReturnValue.expected +++ /dev/null @@ -1 +0,0 @@ -| test.cpp:12:3:12:3 | call to f | Return value from call to $@ is unused. | test.cpp:3:5:3:5 | f | f | \ No newline at end of file diff --git a/cpp/autosar/test/rules/A0-1-2/UnusedReturnValue.qlref b/cpp/autosar/test/rules/A0-1-2/UnusedReturnValue.qlref deleted file mode 100644 index 247484a28e..0000000000 --- a/cpp/autosar/test/rules/A0-1-2/UnusedReturnValue.qlref +++ /dev/null @@ -1 +0,0 @@ -rules/A0-1-2/UnusedReturnValue.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A0-1-2/UnusedReturnValueAutosar.testref b/cpp/autosar/test/rules/A0-1-2/UnusedReturnValueAutosar.testref new file mode 100644 index 0000000000..9c6d99a038 --- /dev/null +++ b/cpp/autosar/test/rules/A0-1-2/UnusedReturnValueAutosar.testref @@ -0,0 +1 @@ +cpp/common/test/rules/unusedreturnvalue/UnusedReturnValue.ql \ No newline at end of file diff --git a/cpp/common/src/codingstandards/cpp/exclusions/cpp/DeadCode.qll b/cpp/common/src/codingstandards/cpp/exclusions/cpp/DeadCode.qll index f11741fde5..5363b75798 100644 --- a/cpp/common/src/codingstandards/cpp/exclusions/cpp/DeadCode.qll +++ b/cpp/common/src/codingstandards/cpp/exclusions/cpp/DeadCode.qll @@ -5,7 +5,7 @@ import codingstandards.cpp.exclusions.RuleMetadata newtype DeadCodeQuery = TUselessAssignmentQuery() or - TUnusedReturnValueQuery() or + TUnusedReturnValueAutosarQuery() or TUnusedLocalFunctionQuery() or TUnusedParameterQuery() or TUnusedVirtualParameterQuery() or @@ -33,11 +33,11 @@ predicate isDeadCodeQueryMetadata(Query query, string queryId, string ruleId, st category = "required" or query = - // `Query` instance for the `unusedReturnValue` query - DeadCodePackage::unusedReturnValueQuery() and + // `Query` instance for the `unusedReturnValueAutosar` query + DeadCodePackage::unusedReturnValueAutosarQuery() and queryId = - // `@id` for the `unusedReturnValue` query - "cpp/autosar/unused-return-value" and + // `@id` for the `unusedReturnValueAutosar` query + "cpp/autosar/unused-return-value-autosar" and ruleId = "A0-1-2" and category = "required" or @@ -185,11 +185,11 @@ module DeadCodePackage { TQueryCPP(TDeadCodePackageQuery(TUselessAssignmentQuery())) } - Query unusedReturnValueQuery() { + Query unusedReturnValueAutosarQuery() { //autogenerate `Query` type result = - // `Query` type for `unusedReturnValue` query - TQueryCPP(TDeadCodePackageQuery(TUnusedReturnValueQuery())) + // `Query` type for `unusedReturnValueAutosar` query + TQueryCPP(TDeadCodePackageQuery(TUnusedReturnValueAutosarQuery())) } Query unusedLocalFunctionQuery() { diff --git a/cpp/common/src/codingstandards/cpp/exclusions/cpp/DeadCode6.qll b/cpp/common/src/codingstandards/cpp/exclusions/cpp/DeadCode6.qll new file mode 100644 index 0000000000..4ce962cdce --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/exclusions/cpp/DeadCode6.qll @@ -0,0 +1,26 @@ +//** THIS FILE IS AUTOGENERATED, DO NOT MODIFY DIRECTLY. **/ +import cpp +import RuleMetadata +import codingstandards.cpp.exclusions.RuleMetadata + +newtype DeadCode6Query = TUnusedReturnValueMisraCppQuery() + +predicate isDeadCode6QueryMetadata(Query query, string queryId, string ruleId, string category) { + query = + // `Query` instance for the `unusedReturnValueMisraCpp` query + DeadCode6Package::unusedReturnValueMisraCppQuery() and + queryId = + // `@id` for the `unusedReturnValueMisraCpp` query + "cpp/misra/unused-return-value-misra-cpp" and + ruleId = "RULE-0-1-2" and + category = "required" +} + +module DeadCode6Package { + Query unusedReturnValueMisraCppQuery() { + //autogenerate `Query` type + result = + // `Query` type for `unusedReturnValueMisraCpp` query + TQueryCPP(TDeadCode6PackageQuery(TUnusedReturnValueMisraCppQuery())) + } +} diff --git a/cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll b/cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll index cad86d2285..10f4029904 100644 --- a/cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll +++ b/cpp/common/src/codingstandards/cpp/exclusions/cpp/RuleMetadata.qll @@ -19,6 +19,7 @@ import Conversions2 import DeadCode import DeadCode3 import DeadCode4 +import DeadCode6 import Declarations import ExceptionSafety import Exceptions1 @@ -91,6 +92,7 @@ newtype TCPPQuery = TDeadCodePackageQuery(DeadCodeQuery q) or TDeadCode3PackageQuery(DeadCode3Query q) or TDeadCode4PackageQuery(DeadCode4Query q) or + TDeadCode6PackageQuery(DeadCode6Query q) or TDeclarationsPackageQuery(DeclarationsQuery q) or TExceptionSafetyPackageQuery(ExceptionSafetyQuery q) or TExceptions1PackageQuery(Exceptions1Query q) or @@ -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 + isDeadCode6QueryMetadata(query, queryId, ruleId, category) or isDeclarationsQueryMetadata(query, queryId, ruleId, category) or isExceptionSafetyQueryMetadata(query, queryId, ruleId, category) or isExceptions1QueryMetadata(query, queryId, ruleId, category) or diff --git a/cpp/common/src/codingstandards/cpp/rules/unusedreturnvalue/UnusedReturnValue.qll b/cpp/common/src/codingstandards/cpp/rules/unusedreturnvalue/UnusedReturnValue.qll new file mode 100644 index 0000000000..3cf6c256fb --- /dev/null +++ b/cpp/common/src/codingstandards/cpp/rules/unusedreturnvalue/UnusedReturnValue.qll @@ -0,0 +1,47 @@ +/** + * Provides a configurable module UnusedReturnValue with a `problems` predicate + * for the following issue: + * The value returned by a function having a non-void return type that is not an + * overloaded operator shall be used. + */ + +import cpp +import codingstandards.cpp.Customizations +import codingstandards.cpp.Exclusions + +signature module UnusedReturnValueConfigSig { + Query getQuery(); +} + +module UnusedReturnValue { + /* + * This query performs a simple syntactic check to ensure that the return value of the function is + * not completely ignored. This matches the examples given in the rule, although the text itself is + * not entirely clear. This means it will not find cases where something is done with the return + * value, but it is not meaningfully read. For example: `int ret_val = f();`, with no subsequent + * access of `ret_val`. However, such a case _would_ be flagged by A0-1-1 - Useless assignment. + */ + + query predicate problems(FunctionCall fc, string message, Function f, string funcName) { + not isExcluded(fc, Config::getQuery()) and + message = "Return value from call to $@ is unused." and + funcName = f.getName() and + // Find function calls in `ExprStmt`s, which indicate the return value is ignored + fc.getParent() instanceof ExprStmt and + // Ignore calls to void functions, which don't return values + not fc.getUnderlyingType() instanceof VoidType and + // Get the function target + f = fc.getTarget() and + // Overloaded (i.e. user defined) operators should behave in the same way as built-in operators, + // so the rule does not require the use of the return value + not f instanceof Operator and + // Exclude cases where the function call is generated within a macro, as the user of the macro is + // not necessarily able to address those results + not fc.isAffectedByMacro() and + // Rule allows disabling this rule where a static_cast or a C-style cast to void is applied + not exists(Cast cast | cast instanceof StaticCast or cast instanceof CStyleCast | + fc.getExplicitlyConverted() = cast and + cast.getActualType() instanceof VoidType + ) + } +} diff --git a/cpp/common/test/rules/unusedreturnvalue/UnusedReturnValue.expected b/cpp/common/test/rules/unusedreturnvalue/UnusedReturnValue.expected new file mode 100644 index 0000000000..96955df6e2 --- /dev/null +++ b/cpp/common/test/rules/unusedreturnvalue/UnusedReturnValue.expected @@ -0,0 +1 @@ +| test.cpp:15:3:15:3 | call to f | Return value from call to $@ is unused. | test.cpp:3:5:3:5 | f | f | diff --git a/cpp/common/test/rules/unusedreturnvalue/UnusedReturnValue.ql b/cpp/common/test/rules/unusedreturnvalue/UnusedReturnValue.ql new file mode 100644 index 0000000000..592adba1e2 --- /dev/null +++ b/cpp/common/test/rules/unusedreturnvalue/UnusedReturnValue.ql @@ -0,0 +1,8 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.unusedreturnvalue.UnusedReturnValue + +module TestFileConfig implements UnusedReturnValueConfigSig { + Query getQuery() { result instanceof TestQuery } +} + +import UnusedReturnValue diff --git a/cpp/autosar/test/rules/A0-1-2/test.cpp b/cpp/common/test/rules/unusedreturnvalue/test.cpp similarity index 86% rename from cpp/autosar/test/rules/A0-1-2/test.cpp rename to cpp/common/test/rules/unusedreturnvalue/test.cpp index 2be7122128..a00e45840f 100644 --- a/cpp/autosar/test/rules/A0-1-2/test.cpp +++ b/cpp/common/test/rules/unusedreturnvalue/test.cpp @@ -5,6 +5,9 @@ void g(int x); class A { public: + A() { + g(2); // Make constructor non-trivial so its call is always extracted. + } A operator+(const A &other); }; @@ -21,6 +24,7 @@ void test_return_val() { a1 + a2; // COMPLIANT - `+` is a call to operator+, but is permitted by the // rule + A a3{}; // COMPLIANT - not function call syntax. (void)f(); // COMPLIANT - explicitly ignoring the return value by C-style cast // to void. std::ignore = f(); // COMPLIANT - explicitly ignoring the return value by diff --git a/cpp/misra/src/rules/RULE-0-1-2/UnusedReturnValueMisraCpp.ql b/cpp/misra/src/rules/RULE-0-1-2/UnusedReturnValueMisraCpp.ql new file mode 100644 index 0000000000..5f2078dabe --- /dev/null +++ b/cpp/misra/src/rules/RULE-0-1-2/UnusedReturnValueMisraCpp.ql @@ -0,0 +1,25 @@ +/** + * @id cpp/misra/unused-return-value-misra-cpp + * @name RULE-0-1-2: The value returned by a function shall be used + * @description The result of a non-void function shall be used if called with function call syntax. + * @kind problem + * @precision very-high + * @problem.severity error + * @tags external/misra/id/rule-0-1-2 + * scope/single-translation-unit + * correctness + * external/misra/enforcement/decidable + * external/misra/obligation/required + */ + +import cpp +import codingstandards.cpp.misra +import codingstandards.cpp.rules.unusedreturnvalue.UnusedReturnValue + +module UnusedReturnValueMisraCppConfig implements UnusedReturnValueConfigSig { + Query getQuery() { + result = DeadCode6Package::unusedReturnValueMisraCppQuery() + } +} + +import UnusedReturnValue diff --git a/cpp/misra/test/rules/RULE-0-1-2/UnusedReturnValueMisraCpp.testref b/cpp/misra/test/rules/RULE-0-1-2/UnusedReturnValueMisraCpp.testref new file mode 100644 index 0000000000..9c6d99a038 --- /dev/null +++ b/cpp/misra/test/rules/RULE-0-1-2/UnusedReturnValueMisraCpp.testref @@ -0,0 +1 @@ +cpp/common/test/rules/unusedreturnvalue/UnusedReturnValue.ql \ No newline at end of file diff --git a/rule_packages/cpp/DeadCode.json b/rule_packages/cpp/DeadCode.json index 4746f86dee..1f917951e8 100644 --- a/rule_packages/cpp/DeadCode.json +++ b/rule_packages/cpp/DeadCode.json @@ -39,7 +39,8 @@ "name": "Unused return value", "precision": "very-high", "severity": "warning", - "short_name": "UnusedReturnValue", + "short_name": "UnusedReturnValueAutosar", + "shared_implementation_short_name": "UnusedReturnValue", "tags": [ "readability", "maintainability" diff --git a/rule_packages/cpp/DeadCode6.json b/rule_packages/cpp/DeadCode6.json new file mode 100644 index 0000000000..6bcf12771d --- /dev/null +++ b/rule_packages/cpp/DeadCode6.json @@ -0,0 +1,26 @@ +{ + "MISRA-C++-2023": { + "RULE-0-1-2": { + "properties": { + "enforcement": "decidable", + "obligation": "required" + }, + "queries": [ + { + "description": "The result of a non-void function shall be used if called with function call syntax.", + "kind": "problem", + "name": "The value returned by a function shall be used", + "precision": "very-high", + "severity": "error", + "short_name": "UnusedReturnValueMisraCpp", + "shared_implementation_short_name": "UnusedReturnValue", + "tags": [ + "scope/single-translation-unit", + "correctness" + ] + } + ], + "title": "The value returned by a function shall be used" + } + } +} \ No newline at end of file diff --git a/rules.csv b/rules.csv index dcc5ee5c5f..08fa09a573 100644 --- a/rules.csv +++ b/rules.csv @@ -826,7 +826,7 @@ c,MISRA-C-2012,RULE-23-8,Yes,Required,,,A default association shall appear as ei cpp,MISRA-C++-2023,RULE-0-0-1,Yes,Required,Decidable,Single Translation Unit,A function shall not contain unreachable statements,M0-1-1,DeadCode3,Medium, cpp,MISRA-C++-2023,RULE-0-0-2,Yes,Advisory,Undecidable,System,Controlling expressions should not be invariant,M0-1-2,DeadCode4,Easy, 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-1-2,Yes,Required,Decidable,Single Translation Unit,The value returned by a function shall be used,A0-1-2,DeadCode6,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-3,Yes,Advisory,Decidable,Single Translation Unit,Types with limited visibility should be used at least once,A0-1-6,DeadCode2,Easy, From 5239d5fe83b9aca31b873d44d3be30249d91f6b2 Mon Sep 17 00:00:00 2001 From: Mike Fairhurst Date: Tue, 10 Feb 2026 21:18:51 -0800 Subject: [PATCH 2/7] Fix formatting --- cpp/autosar/src/rules/A0-1-2/UnusedReturnValueAutosar.ql | 4 +--- cpp/misra/src/rules/RULE-0-1-2/UnusedReturnValueMisraCpp.ql | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/cpp/autosar/src/rules/A0-1-2/UnusedReturnValueAutosar.ql b/cpp/autosar/src/rules/A0-1-2/UnusedReturnValueAutosar.ql index c6175aa001..836a9b4265 100644 --- a/cpp/autosar/src/rules/A0-1-2/UnusedReturnValueAutosar.ql +++ b/cpp/autosar/src/rules/A0-1-2/UnusedReturnValueAutosar.ql @@ -19,9 +19,7 @@ import codingstandards.cpp.autosar import codingstandards.cpp.rules.unusedreturnvalue.UnusedReturnValue module UnusedReturnValueAutosarConfig implements UnusedReturnValueConfigSig { - Query getQuery() { - result = DeadCodePackage::unusedReturnValueAutosarQuery() - } + Query getQuery() { result = DeadCodePackage::unusedReturnValueAutosarQuery() } } import UnusedReturnValue diff --git a/cpp/misra/src/rules/RULE-0-1-2/UnusedReturnValueMisraCpp.ql b/cpp/misra/src/rules/RULE-0-1-2/UnusedReturnValueMisraCpp.ql index 5f2078dabe..2a1f242b34 100644 --- a/cpp/misra/src/rules/RULE-0-1-2/UnusedReturnValueMisraCpp.ql +++ b/cpp/misra/src/rules/RULE-0-1-2/UnusedReturnValueMisraCpp.ql @@ -17,9 +17,7 @@ import codingstandards.cpp.misra import codingstandards.cpp.rules.unusedreturnvalue.UnusedReturnValue module UnusedReturnValueMisraCppConfig implements UnusedReturnValueConfigSig { - Query getQuery() { - result = DeadCode6Package::unusedReturnValueMisraCppQuery() - } + Query getQuery() { result = DeadCode6Package::unusedReturnValueMisraCppQuery() } } import UnusedReturnValue From c38153afe2c479a51b73df64c809c2578ab08f8f Mon Sep 17 00:00:00 2001 From: Mike Fairhurst Date: Tue, 10 Feb 2026 21:22:28 -0800 Subject: [PATCH 3/7] reword change note --- change_notes/2026-02-10-share-autosar-0-1-2.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/change_notes/2026-02-10-share-autosar-0-1-2.md b/change_notes/2026-02-10-share-autosar-0-1-2.md index 5785ed6502..16e9078ad8 100644 --- a/change_notes/2026-02-10-share-autosar-0-1-2.md +++ b/change_notes/2026-02-10-share-autosar-0-1-2.md @@ -1,3 +1,3 @@ - - `A0-1-2` - `UnusedReturnValue.ql`: - - Rule implementation has refactored into a shared library for usage in MISRA C++ ruleset. - - Query file renamed to `UnusedReturnValueAutosar.ql` to distinguish from the MISRA C++ version of the rule. \ No newline at end of file + - `A0-1-2` - `UnusedReturnValueAutosar.ql`: + - Refactors the rule implementation into a shared library for usage in MISRA C++ ruleset. + - Moves old query file from `UnusedReturnValue.ql` to `UnusedReturnValueAutosar.ql` to distinguish from the MISRA C++ version of the rule. \ No newline at end of file From 1ca67895394cfc05a81317fd5b40eeecc07b1321 Mon Sep 17 00:00:00 2001 From: Mike Fairhurst Date: Tue, 10 Feb 2026 21:36:36 -0800 Subject: [PATCH 4/7] Update deviations tests, which copy A0-1-2 --- .../UnusedReturnValue.ql | 32 ++++--------------- .../UnusedReturnValue.ql | 32 ++++--------------- .../UnusedReturnValue.ql | 32 ++++--------------- 3 files changed, 18 insertions(+), 78 deletions(-) diff --git a/cpp/common/test/deviations/deviation_permits_basic_test/UnusedReturnValue.ql b/cpp/common/test/deviations/deviation_permits_basic_test/UnusedReturnValue.ql index 469a7f7f73..1dc771d260 100644 --- a/cpp/common/test/deviations/deviation_permits_basic_test/UnusedReturnValue.ql +++ b/cpp/common/test/deviations/deviation_permits_basic_test/UnusedReturnValue.ql @@ -1,5 +1,5 @@ /** - * @id cpp/autosar/unused-return-value + * @id cpp/autosar/unused-return-value-autosar * @name A0-1-2: Unused return value * @description The value returned by a function having a non-void return type that is not an * overloaded operator shall be used. @@ -17,31 +17,11 @@ import cpp import codingstandards.cpp.CodingStandards import codingstandards.cpp.exclusions.cpp.RuleMetadata +import codingstandards.cpp.rules.unusedreturnvalue.UnusedReturnValue /* This is a copy of an AUTOSAR rule, which we are using for testing purposes. */ -/* - * This query performs a simple syntactic check to ensure that the return value of the function is - * not completely ignored. This matches the examples given in the rule, although the text itself is - * not entirely clear. This means it will not find cases where something is done with the return - * value, but it is not meaningfully read. For example: `int ret_val = f();`, with no subsequent - * access of `ret_val`. However, such a case _would_ be flagged by A0-1-1 - Useless assignment. - */ +module UnusedReturnValueAutosarConfig implements UnusedReturnValueConfigSig { + Query getQuery() { result = DeadCodePackage::unusedReturnValueAutosarQuery() } +} -from FunctionCall fc, Function f -where - not isExcluded(fc, DeadCodePackage::unusedReturnValueQuery()) and - // Find function calls in `ExprStmt`s, which indicate the return value is ignored - fc.getParent() instanceof ExprStmt and - // Ignore calls to void functions, which don't return values - not fc.getType() instanceof VoidType and - // Get the function target - f = fc.getTarget() and - // Overloaded (i.e. user defined) operators should behave in the same way as built-in operators, - // so the rule does not require the use of the return value - not f instanceof Operator and - // Exclude cases where the function call is generated within a macro, as the user of the macro is - // not necessarily able to address thoes results - not fc.isAffectedByMacro() and - // Rule allows disabling this rule where a static_cast is applied - not fc.getExplicitlyConverted().(StaticCast).getActualType() instanceof VoidType -select fc, "Return value from call to $@ is unused.", f, f.getName() +import UnusedReturnValue diff --git a/cpp/common/test/deviations/deviations_basic_test/UnusedReturnValue.ql b/cpp/common/test/deviations/deviations_basic_test/UnusedReturnValue.ql index 469a7f7f73..1dc771d260 100644 --- a/cpp/common/test/deviations/deviations_basic_test/UnusedReturnValue.ql +++ b/cpp/common/test/deviations/deviations_basic_test/UnusedReturnValue.ql @@ -1,5 +1,5 @@ /** - * @id cpp/autosar/unused-return-value + * @id cpp/autosar/unused-return-value-autosar * @name A0-1-2: Unused return value * @description The value returned by a function having a non-void return type that is not an * overloaded operator shall be used. @@ -17,31 +17,11 @@ import cpp import codingstandards.cpp.CodingStandards import codingstandards.cpp.exclusions.cpp.RuleMetadata +import codingstandards.cpp.rules.unusedreturnvalue.UnusedReturnValue /* This is a copy of an AUTOSAR rule, which we are using for testing purposes. */ -/* - * This query performs a simple syntactic check to ensure that the return value of the function is - * not completely ignored. This matches the examples given in the rule, although the text itself is - * not entirely clear. This means it will not find cases where something is done with the return - * value, but it is not meaningfully read. For example: `int ret_val = f();`, with no subsequent - * access of `ret_val`. However, such a case _would_ be flagged by A0-1-1 - Useless assignment. - */ +module UnusedReturnValueAutosarConfig implements UnusedReturnValueConfigSig { + Query getQuery() { result = DeadCodePackage::unusedReturnValueAutosarQuery() } +} -from FunctionCall fc, Function f -where - not isExcluded(fc, DeadCodePackage::unusedReturnValueQuery()) and - // Find function calls in `ExprStmt`s, which indicate the return value is ignored - fc.getParent() instanceof ExprStmt and - // Ignore calls to void functions, which don't return values - not fc.getType() instanceof VoidType and - // Get the function target - f = fc.getTarget() and - // Overloaded (i.e. user defined) operators should behave in the same way as built-in operators, - // so the rule does not require the use of the return value - not f instanceof Operator and - // Exclude cases where the function call is generated within a macro, as the user of the macro is - // not necessarily able to address thoes results - not fc.isAffectedByMacro() and - // Rule allows disabling this rule where a static_cast is applied - not fc.getExplicitlyConverted().(StaticCast).getActualType() instanceof VoidType -select fc, "Return value from call to $@ is unused.", f, f.getName() +import UnusedReturnValue diff --git a/cpp/common/test/deviations/deviations_report_deviated/UnusedReturnValue.ql b/cpp/common/test/deviations/deviations_report_deviated/UnusedReturnValue.ql index 469a7f7f73..1dc771d260 100644 --- a/cpp/common/test/deviations/deviations_report_deviated/UnusedReturnValue.ql +++ b/cpp/common/test/deviations/deviations_report_deviated/UnusedReturnValue.ql @@ -1,5 +1,5 @@ /** - * @id cpp/autosar/unused-return-value + * @id cpp/autosar/unused-return-value-autosar * @name A0-1-2: Unused return value * @description The value returned by a function having a non-void return type that is not an * overloaded operator shall be used. @@ -17,31 +17,11 @@ import cpp import codingstandards.cpp.CodingStandards import codingstandards.cpp.exclusions.cpp.RuleMetadata +import codingstandards.cpp.rules.unusedreturnvalue.UnusedReturnValue /* This is a copy of an AUTOSAR rule, which we are using for testing purposes. */ -/* - * This query performs a simple syntactic check to ensure that the return value of the function is - * not completely ignored. This matches the examples given in the rule, although the text itself is - * not entirely clear. This means it will not find cases where something is done with the return - * value, but it is not meaningfully read. For example: `int ret_val = f();`, with no subsequent - * access of `ret_val`. However, such a case _would_ be flagged by A0-1-1 - Useless assignment. - */ +module UnusedReturnValueAutosarConfig implements UnusedReturnValueConfigSig { + Query getQuery() { result = DeadCodePackage::unusedReturnValueAutosarQuery() } +} -from FunctionCall fc, Function f -where - not isExcluded(fc, DeadCodePackage::unusedReturnValueQuery()) and - // Find function calls in `ExprStmt`s, which indicate the return value is ignored - fc.getParent() instanceof ExprStmt and - // Ignore calls to void functions, which don't return values - not fc.getType() instanceof VoidType and - // Get the function target - f = fc.getTarget() and - // Overloaded (i.e. user defined) operators should behave in the same way as built-in operators, - // so the rule does not require the use of the return value - not f instanceof Operator and - // Exclude cases where the function call is generated within a macro, as the user of the macro is - // not necessarily able to address thoes results - not fc.isAffectedByMacro() and - // Rule allows disabling this rule where a static_cast is applied - not fc.getExplicitlyConverted().(StaticCast).getActualType() instanceof VoidType -select fc, "Return value from call to $@ is unused.", f, f.getName() +import UnusedReturnValue From 0560f658ff124a259ef76d47854d873d076d6154 Mon Sep 17 00:00:00 2001 From: Mike Fairhurst Date: Tue, 10 Feb 2026 21:43:26 -0800 Subject: [PATCH 5/7] Change it to keep query id --- .../{UnusedReturnValueAutosar.ql => UnusedReturnValue.ql} | 8 ++++---- cpp/autosar/test/rules/A0-1-2/UnusedReturnValue.testref | 1 + .../test/rules/A0-1-2/UnusedReturnValueAutosar.testref | 1 - .../UnusedReturnValueShared.qll} | 4 ++-- .../test/rules/unusedreturnvalue/UnusedReturnValue.ql | 8 -------- ...urnValue.expected => UnusedReturnValueShared.expected} | 0 .../rules/unusedreturnvalue/UnusedReturnValueShared.ql | 8 ++++++++ .../src/rules/RULE-0-1-2/UnusedReturnValueMisraCpp.ql | 6 +++--- .../rules/RULE-0-1-2/UnusedReturnValueMisraCpp.testref | 2 +- rule_packages/cpp/DeadCode.json | 4 ++-- rule_packages/cpp/DeadCode6.json | 2 +- 11 files changed, 22 insertions(+), 22 deletions(-) rename cpp/autosar/src/rules/A0-1-2/{UnusedReturnValueAutosar.ql => UnusedReturnValue.ql} (74%) create mode 100644 cpp/autosar/test/rules/A0-1-2/UnusedReturnValue.testref delete mode 100644 cpp/autosar/test/rules/A0-1-2/UnusedReturnValueAutosar.testref rename cpp/common/src/codingstandards/cpp/rules/{unusedreturnvalue/UnusedReturnValue.qll => unusedreturnvalueshared/UnusedReturnValueShared.qll} (94%) delete mode 100644 cpp/common/test/rules/unusedreturnvalue/UnusedReturnValue.ql rename cpp/common/test/rules/unusedreturnvalue/{UnusedReturnValue.expected => UnusedReturnValueShared.expected} (100%) create mode 100644 cpp/common/test/rules/unusedreturnvalue/UnusedReturnValueShared.ql diff --git a/cpp/autosar/src/rules/A0-1-2/UnusedReturnValueAutosar.ql b/cpp/autosar/src/rules/A0-1-2/UnusedReturnValue.ql similarity index 74% rename from cpp/autosar/src/rules/A0-1-2/UnusedReturnValueAutosar.ql rename to cpp/autosar/src/rules/A0-1-2/UnusedReturnValue.ql index 836a9b4265..60412248b7 100644 --- a/cpp/autosar/src/rules/A0-1-2/UnusedReturnValueAutosar.ql +++ b/cpp/autosar/src/rules/A0-1-2/UnusedReturnValue.ql @@ -16,10 +16,10 @@ import cpp import codingstandards.cpp.autosar -import codingstandards.cpp.rules.unusedreturnvalue.UnusedReturnValue +import codingstandards.cpp.rules.unusedreturnvalueshared.UnusedReturnValueShared -module UnusedReturnValueAutosarConfig implements UnusedReturnValueConfigSig { - Query getQuery() { result = DeadCodePackage::unusedReturnValueAutosarQuery() } +module UnusedReturnValueConfig implements UnusedReturnValueSharedConfigSig { + Query getQuery() { result = DeadCodePackage::unusedReturnValueQuery() } } -import UnusedReturnValue +import UnusedReturnValueShared diff --git a/cpp/autosar/test/rules/A0-1-2/UnusedReturnValue.testref b/cpp/autosar/test/rules/A0-1-2/UnusedReturnValue.testref new file mode 100644 index 0000000000..244dae8c0e --- /dev/null +++ b/cpp/autosar/test/rules/A0-1-2/UnusedReturnValue.testref @@ -0,0 +1 @@ +cpp/common/test/rules/unusedreturnvalueshared/UnusedReturnValueShared.ql \ No newline at end of file diff --git a/cpp/autosar/test/rules/A0-1-2/UnusedReturnValueAutosar.testref b/cpp/autosar/test/rules/A0-1-2/UnusedReturnValueAutosar.testref deleted file mode 100644 index 9c6d99a038..0000000000 --- a/cpp/autosar/test/rules/A0-1-2/UnusedReturnValueAutosar.testref +++ /dev/null @@ -1 +0,0 @@ -cpp/common/test/rules/unusedreturnvalue/UnusedReturnValue.ql \ No newline at end of file diff --git a/cpp/common/src/codingstandards/cpp/rules/unusedreturnvalue/UnusedReturnValue.qll b/cpp/common/src/codingstandards/cpp/rules/unusedreturnvalueshared/UnusedReturnValueShared.qll similarity index 94% rename from cpp/common/src/codingstandards/cpp/rules/unusedreturnvalue/UnusedReturnValue.qll rename to cpp/common/src/codingstandards/cpp/rules/unusedreturnvalueshared/UnusedReturnValueShared.qll index 3cf6c256fb..5a9b4445c0 100644 --- a/cpp/common/src/codingstandards/cpp/rules/unusedreturnvalue/UnusedReturnValue.qll +++ b/cpp/common/src/codingstandards/cpp/rules/unusedreturnvalueshared/UnusedReturnValueShared.qll @@ -9,11 +9,11 @@ import cpp import codingstandards.cpp.Customizations import codingstandards.cpp.Exclusions -signature module UnusedReturnValueConfigSig { +signature module UnusedReturnValueSharedConfigSig { Query getQuery(); } -module UnusedReturnValue { +module UnusedReturnValueShared { /* * This query performs a simple syntactic check to ensure that the return value of the function is * not completely ignored. This matches the examples given in the rule, although the text itself is diff --git a/cpp/common/test/rules/unusedreturnvalue/UnusedReturnValue.ql b/cpp/common/test/rules/unusedreturnvalue/UnusedReturnValue.ql deleted file mode 100644 index 592adba1e2..0000000000 --- a/cpp/common/test/rules/unusedreturnvalue/UnusedReturnValue.ql +++ /dev/null @@ -1,8 +0,0 @@ -// GENERATED FILE - DO NOT MODIFY -import codingstandards.cpp.rules.unusedreturnvalue.UnusedReturnValue - -module TestFileConfig implements UnusedReturnValueConfigSig { - Query getQuery() { result instanceof TestQuery } -} - -import UnusedReturnValue diff --git a/cpp/common/test/rules/unusedreturnvalue/UnusedReturnValue.expected b/cpp/common/test/rules/unusedreturnvalue/UnusedReturnValueShared.expected similarity index 100% rename from cpp/common/test/rules/unusedreturnvalue/UnusedReturnValue.expected rename to cpp/common/test/rules/unusedreturnvalue/UnusedReturnValueShared.expected diff --git a/cpp/common/test/rules/unusedreturnvalue/UnusedReturnValueShared.ql b/cpp/common/test/rules/unusedreturnvalue/UnusedReturnValueShared.ql new file mode 100644 index 0000000000..894821756a --- /dev/null +++ b/cpp/common/test/rules/unusedreturnvalue/UnusedReturnValueShared.ql @@ -0,0 +1,8 @@ +// GENERATED FILE - DO NOT MODIFY +import codingstandards.cpp.rules.unusedreturnvalueshared.UnusedReturnValueShared + +module TestFileConfig implements UnusedReturnValueSharedConfigSig { + Query getQuery() { result instanceof TestQuery } +} + +import UnusedReturnValueShared diff --git a/cpp/misra/src/rules/RULE-0-1-2/UnusedReturnValueMisraCpp.ql b/cpp/misra/src/rules/RULE-0-1-2/UnusedReturnValueMisraCpp.ql index 2a1f242b34..6f82d98e38 100644 --- a/cpp/misra/src/rules/RULE-0-1-2/UnusedReturnValueMisraCpp.ql +++ b/cpp/misra/src/rules/RULE-0-1-2/UnusedReturnValueMisraCpp.ql @@ -14,10 +14,10 @@ import cpp import codingstandards.cpp.misra -import codingstandards.cpp.rules.unusedreturnvalue.UnusedReturnValue +import codingstandards.cpp.rules.unusedreturnvalueshared.UnusedReturnValueShared -module UnusedReturnValueMisraCppConfig implements UnusedReturnValueConfigSig { +module UnusedReturnValueMisraCppConfig implements UnusedReturnValueSharedConfigSig { Query getQuery() { result = DeadCode6Package::unusedReturnValueMisraCppQuery() } } -import UnusedReturnValue +import UnusedReturnValueShared diff --git a/cpp/misra/test/rules/RULE-0-1-2/UnusedReturnValueMisraCpp.testref b/cpp/misra/test/rules/RULE-0-1-2/UnusedReturnValueMisraCpp.testref index 9c6d99a038..244dae8c0e 100644 --- a/cpp/misra/test/rules/RULE-0-1-2/UnusedReturnValueMisraCpp.testref +++ b/cpp/misra/test/rules/RULE-0-1-2/UnusedReturnValueMisraCpp.testref @@ -1 +1 @@ -cpp/common/test/rules/unusedreturnvalue/UnusedReturnValue.ql \ No newline at end of file +cpp/common/test/rules/unusedreturnvalueshared/UnusedReturnValueShared.ql \ No newline at end of file diff --git a/rule_packages/cpp/DeadCode.json b/rule_packages/cpp/DeadCode.json index 1f917951e8..1245a8b11d 100644 --- a/rule_packages/cpp/DeadCode.json +++ b/rule_packages/cpp/DeadCode.json @@ -39,8 +39,8 @@ "name": "Unused return value", "precision": "very-high", "severity": "warning", - "short_name": "UnusedReturnValueAutosar", - "shared_implementation_short_name": "UnusedReturnValue", + "short_name": "UnusedReturnValue", + "shared_implementation_short_name": "UnusedReturnValueShared", "tags": [ "readability", "maintainability" diff --git a/rule_packages/cpp/DeadCode6.json b/rule_packages/cpp/DeadCode6.json index 6bcf12771d..4189853c7a 100644 --- a/rule_packages/cpp/DeadCode6.json +++ b/rule_packages/cpp/DeadCode6.json @@ -13,7 +13,7 @@ "precision": "very-high", "severity": "error", "short_name": "UnusedReturnValueMisraCpp", - "shared_implementation_short_name": "UnusedReturnValue", + "shared_implementation_short_name": "UnusedReturnValueShared", "tags": [ "scope/single-translation-unit", "correctness" From 5475ea95f370304022a9bb8d95087e5f4e32277b Mon Sep 17 00:00:00 2001 From: Mike Fairhurst Date: Tue, 10 Feb 2026 21:48:35 -0800 Subject: [PATCH 6/7] Undo change to A0-1-2 query id --- change_notes/2026-02-10-share-autosar-0-1-2.md | 5 ++--- .../src/rules/A0-1-2/UnusedReturnValue.ql | 2 +- .../cpp/exclusions/cpp/DeadCode.qll | 16 ++++++++-------- .../UnusedReturnValue.ql | 11 +++++------ .../deviations_basic_test/UnusedReturnValue.ql | 11 +++++------ .../UnusedReturnValue.ql | 11 +++++------ .../UnusedReturnValueShared.expected | 0 .../UnusedReturnValueShared.ql | 0 .../test.cpp | 0 9 files changed, 26 insertions(+), 30 deletions(-) rename cpp/common/test/rules/{unusedreturnvalue => unusedreturnvalueshared}/UnusedReturnValueShared.expected (100%) rename cpp/common/test/rules/{unusedreturnvalue => unusedreturnvalueshared}/UnusedReturnValueShared.ql (100%) rename cpp/common/test/rules/{unusedreturnvalue => unusedreturnvalueshared}/test.cpp (100%) diff --git a/change_notes/2026-02-10-share-autosar-0-1-2.md b/change_notes/2026-02-10-share-autosar-0-1-2.md index 16e9078ad8..3cc20799c7 100644 --- a/change_notes/2026-02-10-share-autosar-0-1-2.md +++ b/change_notes/2026-02-10-share-autosar-0-1-2.md @@ -1,3 +1,2 @@ - - `A0-1-2` - `UnusedReturnValueAutosar.ql`: - - Refactors the rule implementation into a shared library for usage in MISRA C++ ruleset. - - Moves old query file from `UnusedReturnValue.ql` to `UnusedReturnValueAutosar.ql` to distinguish from the MISRA C++ version of the rule. \ No newline at end of file + - `A0-1-2` - `UnusedReturnValue.ql`: + - Refactors the rule implementation into a shared library for usage in MISRA C++ ruleset. No externally visible changes expected. \ No newline at end of file diff --git a/cpp/autosar/src/rules/A0-1-2/UnusedReturnValue.ql b/cpp/autosar/src/rules/A0-1-2/UnusedReturnValue.ql index 60412248b7..5016650a4b 100644 --- a/cpp/autosar/src/rules/A0-1-2/UnusedReturnValue.ql +++ b/cpp/autosar/src/rules/A0-1-2/UnusedReturnValue.ql @@ -1,5 +1,5 @@ /** - * @id cpp/autosar/unused-return-value-autosar + * @id cpp/autosar/unused-return-value * @name A0-1-2: Unused return value * @description The value returned by a function having a non-void return type that is not an * overloaded operator shall be used. diff --git a/cpp/common/src/codingstandards/cpp/exclusions/cpp/DeadCode.qll b/cpp/common/src/codingstandards/cpp/exclusions/cpp/DeadCode.qll index 5363b75798..f11741fde5 100644 --- a/cpp/common/src/codingstandards/cpp/exclusions/cpp/DeadCode.qll +++ b/cpp/common/src/codingstandards/cpp/exclusions/cpp/DeadCode.qll @@ -5,7 +5,7 @@ import codingstandards.cpp.exclusions.RuleMetadata newtype DeadCodeQuery = TUselessAssignmentQuery() or - TUnusedReturnValueAutosarQuery() or + TUnusedReturnValueQuery() or TUnusedLocalFunctionQuery() or TUnusedParameterQuery() or TUnusedVirtualParameterQuery() or @@ -33,11 +33,11 @@ predicate isDeadCodeQueryMetadata(Query query, string queryId, string ruleId, st category = "required" or query = - // `Query` instance for the `unusedReturnValueAutosar` query - DeadCodePackage::unusedReturnValueAutosarQuery() and + // `Query` instance for the `unusedReturnValue` query + DeadCodePackage::unusedReturnValueQuery() and queryId = - // `@id` for the `unusedReturnValueAutosar` query - "cpp/autosar/unused-return-value-autosar" and + // `@id` for the `unusedReturnValue` query + "cpp/autosar/unused-return-value" and ruleId = "A0-1-2" and category = "required" or @@ -185,11 +185,11 @@ module DeadCodePackage { TQueryCPP(TDeadCodePackageQuery(TUselessAssignmentQuery())) } - Query unusedReturnValueAutosarQuery() { + Query unusedReturnValueQuery() { //autogenerate `Query` type result = - // `Query` type for `unusedReturnValueAutosar` query - TQueryCPP(TDeadCodePackageQuery(TUnusedReturnValueAutosarQuery())) + // `Query` type for `unusedReturnValue` query + TQueryCPP(TDeadCodePackageQuery(TUnusedReturnValueQuery())) } Query unusedLocalFunctionQuery() { diff --git a/cpp/common/test/deviations/deviation_permits_basic_test/UnusedReturnValue.ql b/cpp/common/test/deviations/deviation_permits_basic_test/UnusedReturnValue.ql index 1dc771d260..23bdd9398e 100644 --- a/cpp/common/test/deviations/deviation_permits_basic_test/UnusedReturnValue.ql +++ b/cpp/common/test/deviations/deviation_permits_basic_test/UnusedReturnValue.ql @@ -1,5 +1,5 @@ /** - * @id cpp/autosar/unused-return-value-autosar + * @id cpp/autosar/unused-return-value * @name A0-1-2: Unused return value * @description The value returned by a function having a non-void return type that is not an * overloaded operator shall be used. @@ -17,11 +17,10 @@ import cpp import codingstandards.cpp.CodingStandards import codingstandards.cpp.exclusions.cpp.RuleMetadata -import codingstandards.cpp.rules.unusedreturnvalue.UnusedReturnValue +import codingstandards.cpp.rules.unusedreturnvalueshared.UnusedReturnValueShared -/* This is a copy of an AUTOSAR rule, which we are using for testing purposes. */ -module UnusedReturnValueAutosarConfig implements UnusedReturnValueConfigSig { - Query getQuery() { result = DeadCodePackage::unusedReturnValueAutosarQuery() } +module UnusedReturnValueConfig implements UnusedReturnValueSharedConfigSig { + Query getQuery() { result = DeadCodePackage::unusedReturnValueQuery() } } -import UnusedReturnValue +import UnusedReturnValueShared diff --git a/cpp/common/test/deviations/deviations_basic_test/UnusedReturnValue.ql b/cpp/common/test/deviations/deviations_basic_test/UnusedReturnValue.ql index 1dc771d260..23bdd9398e 100644 --- a/cpp/common/test/deviations/deviations_basic_test/UnusedReturnValue.ql +++ b/cpp/common/test/deviations/deviations_basic_test/UnusedReturnValue.ql @@ -1,5 +1,5 @@ /** - * @id cpp/autosar/unused-return-value-autosar + * @id cpp/autosar/unused-return-value * @name A0-1-2: Unused return value * @description The value returned by a function having a non-void return type that is not an * overloaded operator shall be used. @@ -17,11 +17,10 @@ import cpp import codingstandards.cpp.CodingStandards import codingstandards.cpp.exclusions.cpp.RuleMetadata -import codingstandards.cpp.rules.unusedreturnvalue.UnusedReturnValue +import codingstandards.cpp.rules.unusedreturnvalueshared.UnusedReturnValueShared -/* This is a copy of an AUTOSAR rule, which we are using for testing purposes. */ -module UnusedReturnValueAutosarConfig implements UnusedReturnValueConfigSig { - Query getQuery() { result = DeadCodePackage::unusedReturnValueAutosarQuery() } +module UnusedReturnValueConfig implements UnusedReturnValueSharedConfigSig { + Query getQuery() { result = DeadCodePackage::unusedReturnValueQuery() } } -import UnusedReturnValue +import UnusedReturnValueShared diff --git a/cpp/common/test/deviations/deviations_report_deviated/UnusedReturnValue.ql b/cpp/common/test/deviations/deviations_report_deviated/UnusedReturnValue.ql index 1dc771d260..23bdd9398e 100644 --- a/cpp/common/test/deviations/deviations_report_deviated/UnusedReturnValue.ql +++ b/cpp/common/test/deviations/deviations_report_deviated/UnusedReturnValue.ql @@ -1,5 +1,5 @@ /** - * @id cpp/autosar/unused-return-value-autosar + * @id cpp/autosar/unused-return-value * @name A0-1-2: Unused return value * @description The value returned by a function having a non-void return type that is not an * overloaded operator shall be used. @@ -17,11 +17,10 @@ import cpp import codingstandards.cpp.CodingStandards import codingstandards.cpp.exclusions.cpp.RuleMetadata -import codingstandards.cpp.rules.unusedreturnvalue.UnusedReturnValue +import codingstandards.cpp.rules.unusedreturnvalueshared.UnusedReturnValueShared -/* This is a copy of an AUTOSAR rule, which we are using for testing purposes. */ -module UnusedReturnValueAutosarConfig implements UnusedReturnValueConfigSig { - Query getQuery() { result = DeadCodePackage::unusedReturnValueAutosarQuery() } +module UnusedReturnValueConfig implements UnusedReturnValueSharedConfigSig { + Query getQuery() { result = DeadCodePackage::unusedReturnValueQuery() } } -import UnusedReturnValue +import UnusedReturnValueShared diff --git a/cpp/common/test/rules/unusedreturnvalue/UnusedReturnValueShared.expected b/cpp/common/test/rules/unusedreturnvalueshared/UnusedReturnValueShared.expected similarity index 100% rename from cpp/common/test/rules/unusedreturnvalue/UnusedReturnValueShared.expected rename to cpp/common/test/rules/unusedreturnvalueshared/UnusedReturnValueShared.expected diff --git a/cpp/common/test/rules/unusedreturnvalue/UnusedReturnValueShared.ql b/cpp/common/test/rules/unusedreturnvalueshared/UnusedReturnValueShared.ql similarity index 100% rename from cpp/common/test/rules/unusedreturnvalue/UnusedReturnValueShared.ql rename to cpp/common/test/rules/unusedreturnvalueshared/UnusedReturnValueShared.ql diff --git a/cpp/common/test/rules/unusedreturnvalue/test.cpp b/cpp/common/test/rules/unusedreturnvalueshared/test.cpp similarity index 100% rename from cpp/common/test/rules/unusedreturnvalue/test.cpp rename to cpp/common/test/rules/unusedreturnvalueshared/test.cpp From 066200f4b186637f92aad9ba0408e520ccf1f87d Mon Sep 17 00:00:00 2001 From: Mike Fairhurst Date: Tue, 10 Feb 2026 22:03:12 -0800 Subject: [PATCH 7/7] Reintroduce comment in deviations tests explaining deliberately copied files. --- .../deviations/deviation_permits_basic_test/UnusedReturnValue.ql | 1 + .../test/deviations/deviations_basic_test/UnusedReturnValue.ql | 1 + .../deviations/deviations_report_deviated/UnusedReturnValue.ql | 1 + 3 files changed, 3 insertions(+) diff --git a/cpp/common/test/deviations/deviation_permits_basic_test/UnusedReturnValue.ql b/cpp/common/test/deviations/deviation_permits_basic_test/UnusedReturnValue.ql index 23bdd9398e..a398116bac 100644 --- a/cpp/common/test/deviations/deviation_permits_basic_test/UnusedReturnValue.ql +++ b/cpp/common/test/deviations/deviation_permits_basic_test/UnusedReturnValue.ql @@ -19,6 +19,7 @@ import codingstandards.cpp.CodingStandards import codingstandards.cpp.exclusions.cpp.RuleMetadata import codingstandards.cpp.rules.unusedreturnvalueshared.UnusedReturnValueShared +/* This is a copy of an AUTOSAR rule, which we are using for testing purposes. */ module UnusedReturnValueConfig implements UnusedReturnValueSharedConfigSig { Query getQuery() { result = DeadCodePackage::unusedReturnValueQuery() } } diff --git a/cpp/common/test/deviations/deviations_basic_test/UnusedReturnValue.ql b/cpp/common/test/deviations/deviations_basic_test/UnusedReturnValue.ql index 23bdd9398e..a398116bac 100644 --- a/cpp/common/test/deviations/deviations_basic_test/UnusedReturnValue.ql +++ b/cpp/common/test/deviations/deviations_basic_test/UnusedReturnValue.ql @@ -19,6 +19,7 @@ import codingstandards.cpp.CodingStandards import codingstandards.cpp.exclusions.cpp.RuleMetadata import codingstandards.cpp.rules.unusedreturnvalueshared.UnusedReturnValueShared +/* This is a copy of an AUTOSAR rule, which we are using for testing purposes. */ module UnusedReturnValueConfig implements UnusedReturnValueSharedConfigSig { Query getQuery() { result = DeadCodePackage::unusedReturnValueQuery() } } diff --git a/cpp/common/test/deviations/deviations_report_deviated/UnusedReturnValue.ql b/cpp/common/test/deviations/deviations_report_deviated/UnusedReturnValue.ql index 23bdd9398e..a398116bac 100644 --- a/cpp/common/test/deviations/deviations_report_deviated/UnusedReturnValue.ql +++ b/cpp/common/test/deviations/deviations_report_deviated/UnusedReturnValue.ql @@ -19,6 +19,7 @@ import codingstandards.cpp.CodingStandards import codingstandards.cpp.exclusions.cpp.RuleMetadata import codingstandards.cpp.rules.unusedreturnvalueshared.UnusedReturnValueShared +/* This is a copy of an AUTOSAR rule, which we are using for testing purposes. */ module UnusedReturnValueConfig implements UnusedReturnValueSharedConfigSig { Query getQuery() { result = DeadCodePackage::unusedReturnValueQuery() } }