Author: babadany2999
Date: 2026-08-14T21:48:27+08:00
New Revision: 6b04339b88eb5e7f47233be197e6ba816f52d730

URL: 
https://github.com/llvm/llvm-project/commit/6b04339b88eb5e7f47233be197e6ba816f52d730
DIFF: 
https://github.com/llvm/llvm-project/commit/6b04339b88eb5e7f47233be197e6ba816f52d730.diff

LOG: [Clang][Sema] Fix an ICE where structured binding packs within a lambda 
were not added to the CapturingScopeInfo (#214716)

Fixed a bug where structured binding packs within a lambda were not
added to the `CapturingScopeInfo` during `ActOnDecompositionDeclarator`,
which also led to invalid expressions being considered for delayed
lambda diagnostics, when they should have been diagnosed immediately.

Fixes #214160

Signed-off-by: Baba Dan Constantin <[email protected]>

Added: 
    

Modified: 
    clang/docs/ReleaseNotes.md
    clang/lib/Sema/SemaDeclCXX.cpp
    clang/test/SemaCXX/cxx2c-binding-pack.cpp

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 9a19bb2f2d5c7..6548e8a6028cb 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -400,6 +400,7 @@ features cannot lower the translation-unit ABI level;
 - Fixed a crash when checking scalar type with excess braces. (#GH69213), 
(#GH137845), (#GH198767), (#GH207566), (#GH106180)
 - Fixed an assertion crash when instantiating a nested requirement with an 
invalid constraint. (#GH213575)
 - Clang now defines the GCC-compatible predefined macro `__SIG_ATOMIC_TYPE__`. 
(#GH213895)
+- Fixed an ICE that occurred when a structured binding pack is expanded 
outside the lambda where it was declared. (#GH214160)
 - Fixed a bug where a stray closing curley brace in an OpenMP/OpenACC pragma 
could cause pragma parsing issues when inside of a member function. (#GH214195)
 
 #### Bug Fixes to Compiler Builtins

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index dd95f9220bb9d..5c425a176ff41 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -924,6 +924,11 @@ Sema::ActOnDecompositionDeclarator(Scope *S, Declarator &D,
 
     auto *BD = BindingDecl::Create(Context, DC, B.NameLoc, B.Name, QT);
 
+    if (BD->isParameterPack()) {
+      if (sema::CapturingScopeInfo *CSI = getEnclosingLambdaOrBlock())
+        CSI->LocalPacks.push_back(BD);
+    }
+
     ProcessDeclAttributeList(S, BD, *B.Attrs);
 
     // Find the shadowed declaration before filtering for scope.

diff  --git a/clang/test/SemaCXX/cxx2c-binding-pack.cpp 
b/clang/test/SemaCXX/cxx2c-binding-pack.cpp
index 0b0eb88fe4c98..455e09b7bdab8 100644
--- a/clang/test/SemaCXX/cxx2c-binding-pack.cpp
+++ b/clang/test/SemaCXX/cxx2c-binding-pack.cpp
@@ -259,3 +259,45 @@ static_assert(copy_obj(Arr{}) == 0);
 static_assert(copy_obj(fake_tuple{}) == 12);
 static_assert(copy_obj(Triple{}) == 3);
 }
+
+namespace GH214160 {
+struct S {
+  int x, y;
+};
+
+template <typename = void>
+void f() {
+    ([&]{ auto [...tmp] = S{}; tmp; }(), ...);
+  // expected-error@-1 {{expression contains unexpanded parameter pack 'tmp'}}
+  // expected-error@-2 {{pack expansion does not contain any unexpanded 
parameter packs}}
+}
+
+template void f<void>();
+
+template <typename = void>
+void g() {
+  ([&]{ auto [...tmp] = S{}; ((void)tmp, ...); }(), ...);
+  // expected-error@-1 {{pack expansion does not contain any unexpanded 
parameter packs}}
+}
+
+template void g<void>();
+
+template <typename = void>
+void h() {
+  auto [...tmp] = S{};
+  ([&]{ (void)tmp; }(), ...);
+}
+
+template void h<void>();
+
+template <typename = void>
+void i() {
+  [] {
+    auto [...tmp] = S{};
+    ([&]{ (void)tmp; }(), ...);
+  }();
+}
+
+template void i<void>();
+
+} // namespace GH214160


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

Reply via email to