Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f793d14

Browse filesBrowse files
authored
Merge pull request #64 from lcartey/lcartey/a2-10-5-templates
`A2-10-5`: Exclude variables in template instantiations
2 parents 4de3634 + 3a90ca5 commit f793d14
Copy full SHA for f793d14

5 files changed

+29
-1
lines changed
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `A2-10-5` - `IdentifierNameOfANonMemberObjectWithExternalOrInternalLinkageIsReused.ql`
2+
- Reduce false positives by excluding variable template instantiations.

‎cpp/autosar/src/rules/A2-10-5/IdentifierNameOfANonMemberObjectWithExternalOrInternalLinkageIsReused.ql

Copy file name to clipboardExpand all lines: cpp/autosar/src/rules/A2-10-5/IdentifierNameOfANonMemberObjectWithExternalOrInternalLinkageIsReused.ql
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ where
3232
not isExcluded(o2,
3333
NamingPackage::identifierNameOfANonMemberObjectWithExternalOrInternalLinkageIsReusedQuery()) and
3434
not o1 = o2 and
35-
o1.getName() = o2.getName()
35+
o1.getName() = o2.getName() and
36+
// Only consider variables from uninstantiated templates, to avoid false positives where o1 and
37+
// o2 are the same object across different template instantiations
38+
not o1.isFromTemplateInstantiation(_) and
39+
not o2.isFromTemplateInstantiation(_)
3640
select o2,
3741
"Identifier name of non-member object $@ reuses the identifier name of non-member object $@.", o2,
3842
o2.getName(), o1, o1.getName()
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
| test1a.cpp:6:12:6:13 | g3 | Identifier name of non-member object $@ reuses the identifier name of non-member object $@. | test1a.cpp:6:12:6:13 | g3 | g3 | test1b.cpp:7:12:7:13 | g3 | g3 |
2+
| test1a.cpp:17:43:17:43 | number_two | Identifier name of non-member object $@ reuses the identifier name of non-member object $@. | test1a.cpp:17:43:17:43 | number_two | number_two | test1b.cpp:12:43:12:43 | number_two | number_two |
23
| test1b.cpp:7:12:7:13 | g3 | Identifier name of non-member object $@ reuses the identifier name of non-member object $@. | test1b.cpp:7:12:7:13 | g3 | g3 | test1a.cpp:6:12:6:13 | g3 | g3 |
4+
| test1b.cpp:12:43:12:43 | number_two | Identifier name of non-member object $@ reuses the identifier name of non-member object $@. | test1b.cpp:12:43:12:43 | number_two | number_two | test1a.cpp:17:43:17:43 | number_two | number_two |

‎cpp/autosar/test/rules/A2-10-5/test1a.cpp

Copy file name to clipboardExpand all lines: cpp/autosar/test/rules/A2-10-5/test1a.cpp
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,17 @@ static int g1 = 0;
55
static int g2; // COMPLIANT
66
static int g3 = 1; // NON_COMPLIANT
77
static void f1(){}; // NON_COMPLIANT
8+
9+
// Variable template has multiple declarations: one for the uninstantiated
10+
// template and one for each instantiation
11+
template <class T> constexpr T number_one = T(1); // COMPLIANT
12+
13+
int test() { return number_one<int>; }
14+
15+
long test2() { return number_one<long>; }
16+
17+
template <class T> constexpr T number_two = T(1); // NON_COMPLIANT
18+
19+
int test3() { return number_two<int>; }
20+
21+
long test4() { return number_two<long>; }

‎cpp/autosar/test/rules/A2-10-5/test1b.cpp

Copy file name to clipboardExpand all lines: cpp/autosar/test/rules/A2-10-5/test1b.cpp
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,9 @@ static int g3 = 0; // NON_COMPLIANT
88
}
99

1010
static void f1() {} // NON_COMPLIANT
11+
12+
template <class T> constexpr T number_two = T(1); // NON_COMPLIANT
13+
14+
int test3() { return number_two<int>; }
15+
16+
long test4() { return number_two<long>; }

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.