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

Commit5e17d21

Browse files
authored
Merge pull request#414 from github/lcartey/a0-1-1-ignore-incomplete-or-compiler-generated-vars
`A0-1-1`: Ignore incomplete or compiler generated variables
2 parentsbf45f8c +8043222 commit5e17d21

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

‎change_notes/2023-10-25-a0-1-1.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*`A0-1-1` - address a number of false positive issues:
2+
* Exclude compiler-generated variables, such as those generated for range-based for loops.
3+
* Exclude variables in uninstantiated templates, for which we have no precise data on uses.
4+
* Deviations should now be applied to the useless assignment instead of the variable itself.

‎cpp/autosar/src/rules/A0-1-1/UselessAssignment.ql‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ import codingstandards.cpp.deadcode.UselessAssignments
2020

2121
fromSsaDefinitionultimateDef,InterestingStackVariablev
2222
where
23-
notisExcluded(v, DeadCodePackage::uselessAssignmentQuery())and
23+
notisExcluded(ultimateDef, DeadCodePackage::uselessAssignmentQuery())and
2424
isUselessSsaDefinition(ultimateDef,v)
2525
selectultimateDef,"Definition of $@ is unused.",v,v.getName()

‎cpp/autosar/test/rules/A0-1-1/test.cpp‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,15 @@ int test_useless_assignment(int &x, int p) {
112112
return y;
113113
}
114114

115-
intmain() {return0; }
115+
intmain() {return0; }
116+
117+
#include<vector>
118+
template<typename T>voidtest_range_based_for_loop_template() {
119+
std::vector<A> values_;
120+
for (auto &elem : values_) {// COMPLIANT - should not report either elem or
121+
// the compiler generated (__range)
122+
// variable in the uninstantiated
123+
// template
124+
elem;
125+
}
126+
}

‎cpp/common/src/codingstandards/cpp/deadcode/UselessAssignments.qll‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ class InterestingStackVariable extends StackVariable {
4343
// A reference parameter can have an affect outside the enclosing function
4444
notmayEscape(this)and
4545
// Not a loop control variable, explicitly excluded
46-
notthisinstanceofLoopControlVariable
46+
notthisinstanceofLoopControlVariableand
47+
// Ignore variables in uninstantiated templates
48+
notthis.isFromUninstantiatedTemplate(_)and
49+
// Ignore compiler generated variables, such as those generated for range based for loops
50+
notthis.isCompilerGenerated()
4751
}
4852
}
4953

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp