Skip to content

Commit 6336fd2

Browse files
committed
A7-1-5: Expand test cases
Add extra test cases which highlight issues with range based for loops.
1 parent 618dac5 commit 6336fd2

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

cpp/autosar/test/rules/A7-1-5/AutoSpecifierNotUsedAppropriatelyInVariableDefinition.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
| test.cpp:27:8:27:8 | a | Use of auto in variable definition is not the result of a function call, lambda expression, or non-fundamental type initializer. |
55
| test.cpp:28:8:28:8 | b | Use of auto in variable definition is not the result of a function call, lambda expression, or non-fundamental type initializer. |
66
| test.cpp:81:10:81:10 | a | Use of auto in variable definition is not the result of a function call, lambda expression, or non-fundamental type initializer. |
7-
| test.cpp:111:19:111:19 | a | Use of auto in variable definition is not the result of a function call, lambda expression, or non-fundamental type initializer. |
7+
| test.cpp:111:13:111:13 | a | Use of auto in variable definition is not the result of a function call, lambda expression, or non-fundamental type initializer. |

cpp/autosar/test/rules/A7-1-5/test.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,30 @@ void instantiate() {
106106
t381.test_381_1();
107107
t381.test_381_2();
108108
}
109-
109+
class Foo {};
110110
void test_loop() {
111-
for (const auto a : {8, 9, 10}) { // NON_COMPLIANT - a is initialized with a
112-
// non-constant initializer
111+
for (auto a : {8, 9, 10}) { // NON_COMPLIANT - a is initialized with a
112+
// non-constant initializer
113113
a;
114114
}
115115

116116
std::vector<int> v = {1, 2, 3};
117-
for (const auto a : v) { // COMPLIANT - a is intialized with a function call
117+
for (auto &a : v) { // COMPLIANT - a is intialized with a function call
118+
a;
119+
}
120+
121+
Foo f1;
122+
Foo f2;
123+
for (auto &a : {f1, f2}) { // COMPLIANT - initialized with a non-fundamental
124+
// type
125+
a;
126+
}
127+
}
128+
129+
template <typename T> void test_template(std::vector<T> v2) {
130+
for (auto &a : v2) { // COMPLIANT - a is intialized with a function call
118131
a;
119132
}
120-
}
133+
}
134+
135+
void test_template_instantiation() { test_template<int>({1, 2, 3}); }

0 commit comments

Comments
 (0)