https://github.com/nataliakokoromyti created 
https://github.com/llvm/llvm-project/pull/177918

Removed an incorrect assertion in RequireLiteralType - it assumed 
getDestructor() never returns null, but malformed destructors can cause that. 
The null check after it already handled it.

Fixes #177894.

>From 08b98ba6e6e271bfe257018a4a81db82335c13ea Mon Sep 17 00:00:00 2001
From: nataliakokoromyti <[email protected]>
Date: Mon, 26 Jan 2026 01:49:13 -0800
Subject: [PATCH] fix assertion failure with malformed destructor in literal
 type check

---
 clang/docs/ReleaseNotes.rst         |  1 +
 clang/lib/Sema/SemaType.cpp         |  1 -
 clang/test/SemaCXX/literal-type.cpp | 11 +++++++++++
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a5340a31d4fe9..bcecd448c3321 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -185,6 +185,7 @@ Bug Fixes to Attribute Support
 Bug Fixes to C++ Support
 ^^^^^^^^^^^^^^^^^^^^^^^^
 - Fixed a crash when instantiating ``requires`` expressions involving 
substitution failures in C++ concepts. (#GH176402)
+- Fixed an assertion failure when checking literal types with malformed 
destructor declarations. (#GH177894)
 
 Bug Fixes to AST Handling
 ^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 91d36f0502d85..d9110ab79ee6e 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -9679,7 +9679,6 @@ bool Sema::RequireLiteralType(SourceLocation Loc, 
QualType T,
     // destructors. If this class's destructor is non-trivial / non-constexpr,
     // it must be user-declared.
     CXXDestructorDecl *Dtor = RD->getDestructor();
-    assert(Dtor && "class has literal fields and bases but no dtor?");
     if (!Dtor)
       return true;
 
diff --git a/clang/test/SemaCXX/literal-type.cpp 
b/clang/test/SemaCXX/literal-type.cpp
index 44b6ba62262fd..e15a060d8ab38 100644
--- a/clang/test/SemaCXX/literal-type.cpp
+++ b/clang/test/SemaCXX/literal-type.cpp
@@ -176,3 +176,14 @@ 
static_assert(__is_literal(UnionWithNonLiteralMemberConstexprDtor2), "fail");
 #endif
 }
 #endif
+
+namespace GH177894 {
+struct S {
+  ~S() = (0); // expected-error {{initializer on function does not look like a 
pure-specifier}}
+};
+
+#if __cplusplus < 202302L
+constexpr void foo() { S s; } // expected-error {{variable of non-literal type 
'S' cannot be defined in a constexpr function before C++23}}
+#endif
+}
+#endif

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

Reply via email to