https://github.com/akash-manna-sky updated 
https://github.com/llvm/llvm-project/pull/219270

>From 63c6a9c0195c05eaebcd025e823a4fb5d6e2fcc3 Mon Sep 17 00:00:00 2001
From: Akash Manna <[email protected]>
Date: Fri, 28 Aug 2026 00:45:12 +0530
Subject: [PATCH 1/2] [clang][Parse] Fix assertion on parenthesized structured
 binding followed by a function body

ParseDirectDeclarator returns right after parsing a structured binding
declarator, since `[a, b]` cannot be followed by declarator chunks. When
the binding list is inside grouping parens, though, the outer
ParseDirectDeclarator carried on and parsed a following `()` as a
function declarator, so `([a, b])() {}` was treated as a function
definition and ActOnStartOfFunctionDef received a DecompositionDecl.

Stop after the paren declarator as well.

Fixes #218144
Fixes #193687
---
 clang/docs/ReleaseNotes.md     |  4 ++++
 clang/lib/Parse/ParseDecl.cpp  |  5 +++++
 clang/test/Parser/GH218144.cpp | 30 ++++++++++++++++++++++++++++++
 3 files changed, 39 insertions(+)
 create mode 100644 clang/test/Parser/GH218144.cpp

diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 332e0bfdb3a8b..aaad27bd47408 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -536,6 +536,10 @@ features cannot lower the translation-unit ABI level;
   parameter that follows a parameter pack (e.g.
   `template <typename... T> S::S(T..., int = 10) {}`).  (#GH216211)
 
+- Fixed an assertion failure when a parenthesized structured binding declarator
+  was followed by a function declarator and body (e.g. ``([a, b])() {}``).
+  (#GH218144, #GH193687)
+
 #### Bug Fixes to AST Handling
 
 - Fixed a non-deterministic ordering of unused local typedefs that made
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 2bbc76fc7c4df..11ba2b81baacc 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -6862,6 +6862,11 @@ void Parser::ParseDirectDeclarator(Declarator &D) {
     // Example: 'char (*X)'   or 'int (*XX)(void)'
     ParseParenDeclarator(D);
 
+    // As above, a structured binding declarator cannot be followed by any
+    // declarator chunks.
+    if (D.isDecompositionDeclarator())
+      return;
+
     // If the declarator was parenthesized, we entered the declarator
     // scope when parsing the parenthesized declarator, then exited
     // the scope already. Re-enter the scope, if we need to.
diff --git a/clang/test/Parser/GH218144.cpp b/clang/test/Parser/GH218144.cpp
new file mode 100644
index 0000000000000..d915047ad52ea
--- /dev/null
+++ b/clang/test/Parser/GH218144.cpp
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++26 -fsyntax-only -verify %s
+
+b;([c,ac])(){}
+// expected-error@-1 2 {{a type specifier is required for all declarations}}
+// expected-error@-2 {{structured binding declaration cannot be declared with 
parentheses}}
+// expected-error@-3 {{expected expression}}
+// expected-error@-4 {{expected ';' after top level declarator}}
+
+([d])(){d}
+// expected-error@-1 {{a type specifier is required for all declarations}}
+// expected-error@-2 {{structured binding declaration cannot be declared with 
parentheses}}
+// expected-error@-3 {{expected expression}}
+// expected-error@-4 {{expected ';' after top level declarator}}
+
+auto ([a])() {}
+// expected-error@-1 {{structured binding declaration cannot be declared with 
parentheses}}
+// expected-error@-2 {{expected expression}}
+// expected-error@-3 {{expected ';' after top level declarator}}
+
+auto (([x, y, z]))() {}
+// expected-error@-1 {{structured binding declaration cannot be declared with 
parentheses}}
+// expected-error@-2 {{expected expression}}
+// expected-error@-3 {{expected ';' after top level declarator}}
+
+struct S {
+  ([m, n])() {}
+  // expected-error@-1 {{structured binding declaration not permitted in this 
context}}
+  // expected-error@-2 {{expected ';' at end of declaration list}}
+};

>From 164fb970ff9728be97fdf0245fea43490821433d Mon Sep 17 00:00:00 2001
From: Akash Manna <[email protected]>
Date: Sat, 29 Aug 2026 20:34:32 +0530
Subject: [PATCH 2/2] [clang][ReleaseNotes] Fix assertion failure for
 parenthesized structured binding followed by function body

---
 clang/docs/ReleaseNotes.md | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index aaad27bd47408..e715e940e0847 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -496,6 +496,10 @@ features cannot lower the translation-unit ABI level;
   parsed where a nested-name-specifier could appear (e.g. ``int decltype = 
0;``).
   Clang now diagnoses the error instead of asserting. (#GH211207)
 
+- Fixed an assertion failure when a parenthesized structured binding declarator
+  was followed by a function declarator and body (e.g. ``([a, b])() {}``).
+  (#GH218144, #GH193687)
+
 - Fixed a crash when computing the implicit deletion of a defaulted comparison
   operator required an access check that ran while an enclosing declaration
   was still being parsed. (#GH210692)
@@ -536,10 +540,6 @@ features cannot lower the translation-unit ABI level;
   parameter that follows a parameter pack (e.g.
   `template <typename... T> S::S(T..., int = 10) {}`).  (#GH216211)
 
-- Fixed an assertion failure when a parenthesized structured binding declarator
-  was followed by a function declarator and body (e.g. ``([a, b])() {}``).
-  (#GH218144, #GH193687)
-
 #### Bug Fixes to AST Handling
 
 - Fixed a non-deterministic ordering of unused local typedefs that made

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to