Skip to content

Commit aaac22d

Browse files
authored
Merge pull request #1174 from github/michaelrfairhurst/allow-destructured-assignment
Fix #1172, structured bindings reported by RULE-10-0-1
2 parents d8de842 + 59acf52 commit aaac22d

3 files changed

Lines changed: 10 additions & 0 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `RULE-10-0-1`, `M8-0-1` - `MultipleLocalDeclarators.qll`:
2+
- Added a check to ignore structured bindings from C++17, which are explicitly allowed by RULE 10-0-1 and serve a unique useful purpose.

cpp/common/src/codingstandards/cpp/rules/multiplelocaldeclarators/MultipleLocalDeclarators.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,7 @@ query predicate problems(DeclStmt ds, string message) {
1616
count(Declaration d | d = ds.getADeclaration()) > 1 and
1717
// Not a compiler generated `DeclStmt`, such as in the range-based for loop
1818
not ds.isCompilerGenerated() and
19+
// Not a structured binding
20+
not ds.getADeclaration().(Variable).isStructuredBinding() and
1921
message = "Declaration list contains more than one declaration."
2022
}

cpp/common/test/rules/multiplelocaldeclarators/test.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,10 @@ void test_loop(std::vector<ClassA> v) {
2121
for (const auto b : v) { // COMPLIANT - DeclStmt is compiler generated
2222
b;
2323
}
24+
}
25+
26+
#include <utility>
27+
void f2() {
28+
std::pair<int, int> p1;
29+
auto [a, b] = p1; // COMPLIANT - structured bindings.
2430
}

0 commit comments

Comments
 (0)