https://github.com/fitermay updated 
https://github.com/llvm/llvm-project/pull/205973

>From fdb4dc25a1243b9d2280d2a4cbcdfb9bacd8a19b Mon Sep 17 00:00:00 2001
From: Yuli Fiterman <[email protected]>
Date: Thu, 25 Jun 2026 21:40:35 -0700
Subject: [PATCH 1/2] [Clang][Sema] Fix crash on init-list of array with
 incomplete element type

Bail out of checkDestructorReference when the element type is an
incomplete record. Sema::LookupDestructor (via LookupSpecialMember)
asserts that the record is fully defined; reaching it with a
forward-declared class triggered an assertion crash during error
recovery for init-lists of incomplete element types.

Fixes #140685.
---
 clang/docs/ReleaseNotes.rst                    |  1 +
 clang/lib/Sema/SemaInit.cpp                    |  7 ++++++-
 .../init-list-incomplete-dtor-crash.cpp        | 18 ++++++++++++++++++
 3 files changed, 25 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/init-list-incomplete-dtor-crash.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a2439ccb0452a..e69dba182e1dd 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -816,6 +816,7 @@ Bug Fixes to C++ Support
 - Fixed an issue where Clang incorrectly accepted invalid unqualified uses of 
local nested class names outside their declaring scope. (#GH184622)
 - Fixed a crash when parsing invalid friend declaration with storage-class 
specifier. (#GH186569)
 - Fixed a missing vtable for ``dynamic_cast<FinalClass *>(this)`` in a 
function template. (#GH198511)
+- Fixed an assertion failure during init-list checking of an array whose 
element type is an incomplete (forward-declared) class. (#GH140685)
 
 Bug Fixes to AST Handling
 ^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 8f685feac4beb..dad9c8c972dd9 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -2094,7 +2094,12 @@ void InitListChecker::CheckVectorType(const 
InitializedEntity &Entity,
 static bool checkDestructorReference(QualType ElementType, SourceLocation Loc,
                                      Sema &SemaRef) {
   auto *CXXRD = ElementType->getAsCXXRecordDecl();
-  if (!CXXRD)
+  // Bail out on incomplete record types: a forward-declared class has no
+  // destructor to look up, and `LookupDestructor` (via `LookupSpecialMember`)
+  // asserts that the record is fully defined. Error recovery for init lists
+  // of incomplete element types reaches this point even after the parser has
+  // already diagnosed the incompleteness.
+  if (!CXXRD || !CXXRD->hasDefinition())
     return false;
 
   CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(CXXRD);
diff --git a/clang/test/SemaCXX/init-list-incomplete-dtor-crash.cpp 
b/clang/test/SemaCXX/init-list-incomplete-dtor-crash.cpp
new file mode 100644
index 0000000000000..f5ea89a3450a7
--- /dev/null
+++ b/clang/test/SemaCXX/init-list-incomplete-dtor-crash.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify %s
+
+// Regression test for https://github.com/llvm/llvm-project/issues/140685
+//
+// List-initialization of an array whose element type is an incomplete
+// (forward-declared) class triggered destructor lookup on the incomplete
+// type, hitting an assertion in Sema::LookupSpecialMember.
+
+namespace gh140685 {
+struct MoveOnly; // expected-note {{forward declaration of 
'gh140685::MoveOnly'}}
+
+void test() {
+  MoveOnly(&&list)[1] = {};
+  // expected-error@-1 {{initialization of incomplete type 'MoveOnly'}}
+  // expected-note@-2 {{in implicit initialization of array element 0 with 
omitted initializer}}
+  // expected-note@-3 {{in initialization of temporary of type 'MoveOnly[1]' 
created to list-initialize this reference}}
+}
+} // namespace gh140685

>From ff14ed273df390a0fb24706293c804738b28885c Mon Sep 17 00:00:00 2001
From: Yuli Fiterman <[email protected]>
Date: Fri, 26 Jun 2026 09:00:27 -0700
Subject: [PATCH 2/2] Update clang/docs/ReleaseNotes.rst

Co-authored-by: Corentin Jabot <[email protected]>
---
 clang/docs/ReleaseNotes.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e69dba182e1dd..a09f2575e1111 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -816,7 +816,7 @@ Bug Fixes to C++ Support
 - Fixed an issue where Clang incorrectly accepted invalid unqualified uses of 
local nested class names outside their declaring scope. (#GH184622)
 - Fixed a crash when parsing invalid friend declaration with storage-class 
specifier. (#GH186569)
 - Fixed a missing vtable for ``dynamic_cast<FinalClass *>(this)`` in a 
function template. (#GH198511)
-- Fixed an assertion failure during init-list checking of an array whose 
element type is an incomplete (forward-declared) class. (#GH140685)
+- Fixed an assertion failure during init-list checking of an array whose 
element type is an incomplete class. (#GH140685)
 
 Bug Fixes to AST Handling
 ^^^^^^^^^^^^^^^^^^^^^^^^^

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

Reply via email to