Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitf793d14

Browse files
authored
Merge pull request#64 from lcartey/lcartey/a2-10-5-templates
`A2-10-5`: Exclude variables in template instantiations
2 parents4de3634 +3a90ca5 commitf793d14

File tree

5 files changed

+29
-1
lines changed

5 files changed

+29
-1
lines changed
Lines 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‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ where
3232
notisExcluded(o2,
3333
NamingPackage::identifierNameOfANonMemberObjectWithExternalOrInternalLinkageIsReusedQuery())and
3434
noto1=o2and
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+
noto1.isFromTemplateInstantiation(_)and
39+
noto2.isFromTemplateInstantiation(_)
3640
selecto2,
3741
"Identifier name of non-member object $@ reuses the identifier name of non-member object $@.",o2,
3842
o2.getName(),o1,o1.getName()
Lines changed: 2 additions & 0 deletions
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‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,17 @@ static int g1 = 0;
55
staticint g2;// COMPLIANT
66
staticint g3 =1;// NON_COMPLIANT
77
staticvoidf1(){};// NON_COMPLIANT
8+
9+
// Variable template has multiple declarations: one for the uninstantiated
10+
// template and one for each instantiation
11+
template<classT>constexpr T number_one = T(1);// COMPLIANT
12+
13+
inttest() {return number_one<int>; }
14+
15+
longtest2() {return number_one<long>; }
16+
17+
template<classT>constexpr T number_two = T(1);// NON_COMPLIANT
18+
19+
inttest3() {return number_two<int>; }
20+
21+
longtest4() {return number_two<long>; }

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

Lines 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
staticvoidf1() {}// NON_COMPLIANT
11+
12+
template<classT>constexpr T number_two = T(1);// NON_COMPLIANT
13+
14+
inttest3() {return number_two<int>; }
15+
16+
longtest4() {return number_two<long>; }

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp