Skip to content

Commit 5c4e72d

Browse files
committed
M8-0-1: Exclude compiler generated DeclStmts
These can occur, for example, in range-based for loops.
1 parent 738c5b8 commit 5c4e72d

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

cpp/autosar/src/rules/M8-0-1/MultipleLocalDeclarators.ql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,7 @@ import codingstandards.cpp.autosar
2020
from DeclStmt ds
2121
where
2222
not isExcluded(ds, InitializationPackage::multipleLocalDeclaratorsQuery()) and
23-
count(ds.getADeclaration()) > 1
23+
count(Declaration d | d = ds.getADeclaration()) > 1 and
24+
// Not a compiler generated `DeclStmt`, such as in the range-based for loop
25+
not ds.isCompilerGenerated()
2426
select ds, "Declaration list contains more than one declaration."

cpp/autosar/test/rules/M8-0-1/test.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,10 @@ class ClassA {
1515
int m1, m2; // NON_COMPLIANT
1616
int m3; // COMPLIANT
1717
};
18+
19+
#include <vector>
20+
void test_loop(std::vector<ClassA> v) {
21+
for (const auto b : v) { // COMPLIANT - DeclStmt is compiler generated
22+
b;
23+
}
24+
}

0 commit comments

Comments
 (0)