diff --git a/change_notes/2024-02-12-exclusion-A2-10-4.md b/change_notes/2024-02-12-exclusion-A2-10-4.md new file mode 100644 index 0000000000..ccaf302dd1 --- /dev/null +++ b/change_notes/2024-02-12-exclusion-A2-10-4.md @@ -0,0 +1,2 @@ +- `A2-10-4` - `IdentifierNameOfStaticNonMemberObjectReusedInNamespace.ql`: + - Fix FP reported in #385. Addresses incorrect detection of partially specialized template variables as conflicting reuses. \ No newline at end of file diff --git a/cpp/autosar/src/rules/A2-10-4/IdentifierNameOfStaticNonMemberObjectReusedInNamespace.ql b/cpp/autosar/src/rules/A2-10-4/IdentifierNameOfStaticNonMemberObjectReusedInNamespace.ql index ba24ada376..e04bb89cfa 100644 --- a/cpp/autosar/src/rules/A2-10-4/IdentifierNameOfStaticNonMemberObjectReusedInNamespace.ql +++ b/cpp/autosar/src/rules/A2-10-4/IdentifierNameOfStaticNonMemberObjectReusedInNamespace.ql @@ -20,7 +20,9 @@ class CandidateVariable extends Variable { CandidateVariable() { hasDefinition() and isStatic() and - not this instanceof MemberVariable + not this instanceof MemberVariable and + //exclude partially specialized template variables + not exists(TemplateVariable v | this = v.getAnInstantiation()) } } diff --git a/cpp/autosar/src/rules/M3-9-1/TypesNotIdenticalInReturnDeclarations.ql b/cpp/autosar/src/rules/M3-9-1/TypesNotIdenticalInReturnDeclarations.ql index b99c656692..2792850dba 100644 --- a/cpp/autosar/src/rules/M3-9-1/TypesNotIdenticalInReturnDeclarations.ql +++ b/cpp/autosar/src/rules/M3-9-1/TypesNotIdenticalInReturnDeclarations.ql @@ -15,8 +15,6 @@ import cpp import codingstandards.cpp.autosar -import cpp -import codingstandards.cpp.autosar from FunctionDeclarationEntry f1, FunctionDeclarationEntry f2 where diff --git a/cpp/autosar/test/rules/A2-10-4/test1a.cpp b/cpp/autosar/test/rules/A2-10-4/test1a.cpp index 4c6ec898ed..8511fffa92 100644 --- a/cpp/autosar/test/rules/A2-10-4/test1a.cpp +++ b/cpp/autosar/test/rules/A2-10-4/test1a.cpp @@ -13,4 +13,10 @@ namespace ns3 { static void f1() {} void f2() {} + +// Variable templates can cause false positives +template static int number_one = 0; // COMPLIANT + +template <> static int number_one<1> = 1; // COMPLIANT +template <> static int number_one<2> = 2; // COMPLIANT } // namespace ns3 \ No newline at end of file