Skip to content

A2-10-4: exclude partially specialized template variables #531

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 16, 2024
Merged
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
2 changes: 2 additions & 0 deletions change_notes/2024-02-12-exclusion-A2-10-4.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

import cpp
import codingstandards.cpp.autosar
import cpp
import codingstandards.cpp.autosar

from FunctionDeclarationEntry f1, FunctionDeclarationEntry f2
where
Expand Down
6 changes: 6 additions & 0 deletions cpp/autosar/test/rules/A2-10-4/test1a.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@ namespace ns3 {
static void f1() {}

void f2() {}

// Variable templates can cause false positives
template <int x> static int number_one = 0; // COMPLIANT

template <> static int number_one<1> = 1; // COMPLIANT
template <> static int number_one<2> = 2; // COMPLIANT
} // namespace ns3