Skip to content

Commit 3ead29f

Browse files
authored
Merge pull request #531 from knewbury01/knewbury01/fix-385
A2-10-4: exclude partially specialized template variables
2 parents 31f5ba4 + 0516f5f commit 3ead29f

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `A2-10-4` - `IdentifierNameOfStaticNonMemberObjectReusedInNamespace.ql`:
2+
- Fix FP reported in #385. Addresses incorrect detection of partially specialized template variables as conflicting reuses.

cpp/autosar/src/rules/A2-10-4/IdentifierNameOfStaticNonMemberObjectReusedInNamespace.ql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ class CandidateVariable extends Variable {
2020
CandidateVariable() {
2121
hasDefinition() and
2222
isStatic() and
23-
not this instanceof MemberVariable
23+
not this instanceof MemberVariable and
24+
//exclude partially specialized template variables
25+
not exists(TemplateVariable v | this = v.getAnInstantiation())
2426
}
2527
}
2628

cpp/autosar/src/rules/M3-9-1/TypesNotIdenticalInReturnDeclarations.ql

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
import cpp
1717
import codingstandards.cpp.autosar
18-
import cpp
19-
import codingstandards.cpp.autosar
2018

2119
from FunctionDeclarationEntry f1, FunctionDeclarationEntry f2
2220
where

cpp/autosar/test/rules/A2-10-4/test1a.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,10 @@ namespace ns3 {
1313
static void f1() {}
1414

1515
void f2() {}
16+
17+
// Variable templates can cause false positives
18+
template <int x> static int number_one = 0; // COMPLIANT
19+
20+
template <> static int number_one<1> = 1; // COMPLIANT
21+
template <> static int number_one<2> = 2; // COMPLIANT
1622
} // namespace ns3

0 commit comments

Comments
 (0)