diff --git a/change_notes/2026-08-19-allow-structured-bindings.md b/change_notes/2026-08-19-allow-structured-bindings.md new file mode 100644 index 0000000000..f54d9c4d83 --- /dev/null +++ b/change_notes/2026-08-19-allow-structured-bindings.md @@ -0,0 +1,2 @@ +- `RULE-10-0-1`, `M8-0-1` - `MultipleLocalDeclarators.qll`: + - 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. \ No newline at end of file diff --git a/cpp/common/src/codingstandards/cpp/rules/multiplelocaldeclarators/MultipleLocalDeclarators.qll b/cpp/common/src/codingstandards/cpp/rules/multiplelocaldeclarators/MultipleLocalDeclarators.qll index 2269f36d97..b771c3b713 100644 --- a/cpp/common/src/codingstandards/cpp/rules/multiplelocaldeclarators/MultipleLocalDeclarators.qll +++ b/cpp/common/src/codingstandards/cpp/rules/multiplelocaldeclarators/MultipleLocalDeclarators.qll @@ -16,5 +16,7 @@ query predicate problems(DeclStmt ds, string message) { count(Declaration d | d = ds.getADeclaration()) > 1 and // Not a compiler generated `DeclStmt`, such as in the range-based for loop not ds.isCompilerGenerated() and + // Not a structured binding + not ds.getADeclaration().(Variable).isStructuredBinding() and message = "Declaration list contains more than one declaration." } diff --git a/cpp/common/test/rules/multiplelocaldeclarators/test.cpp b/cpp/common/test/rules/multiplelocaldeclarators/test.cpp index cf664e4b34..9fae25d103 100644 --- a/cpp/common/test/rules/multiplelocaldeclarators/test.cpp +++ b/cpp/common/test/rules/multiplelocaldeclarators/test.cpp @@ -21,4 +21,10 @@ void test_loop(std::vector v) { for (const auto b : v) { // COMPLIANT - DeclStmt is compiler generated b; } +} + +#include +void f2() { + std::pair p1; + auto [a, b] = p1; // COMPLIANT - structured bindings. } \ No newline at end of file