Skip to content

Commit 6c0d54c

Browse files
committed
A7-1-5: Exclude compiler generated variables
A7-1-5 should only apply to non-compiler generated variables. This commit adds a new test case which shows an example which, on some platforms, will cause the compiler to generate a __range variable that is flagged by the query before this change. Note: I have been unable to replicate the problem in a unit test.
1 parent 5c4e72d commit 6c0d54c

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

cpp/autosar/src/rules/A7-1-5/AutoSpecifierNotUsedAppropriatelyInVariableDefinition.ql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ where
3939
v.getInitializer().getExpr() instanceof LambdaExpression
4040
or
4141
v.getInitializer().getExpr() instanceof ClassAggregateLiteral
42-
)
42+
) and
43+
// Exclude compiler generated variables
44+
not v.isCompilerGenerated()
4345
select v,
4446
"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/AutoSpecifierNotUsedAppropriatelyInVariableDefinition.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +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. |

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,10 @@ void instantiate() {
105105
Test_381<int> t381;
106106
t381.test_381_1();
107107
t381.test_381_2();
108+
}
109+
110+
void test_loop() {
111+
for (const auto a : {8, 9, 10}) {
112+
a;
113+
}
108114
}

0 commit comments

Comments
 (0)