Skip to content

Commit b8a527c

Browse files
committed
A0-1-1: Ignore incomplete or compiler generated vars
1 parent c719039 commit b8a527c

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

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-
int main() { return 0; }
115+
int main() { return 0; }
116+
117+
#include <vector>
118+
template <typename T> void test_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
not mayEscape(this) and
4545
// Not a loop control variable, explicitly excluded
46-
not this instanceof LoopControlVariable
46+
not this instanceof LoopControlVariable and
47+
// Ignore variables in uninstantiated templates
48+
not this.isFromUninstantiatedTemplate(_) and
49+
// Ignore compiler generated variables, such as those generated for range based for loops
50+
not this.isCompilerGenerated()
4751
}
4852
}
4953

0 commit comments

Comments
 (0)