[clang] [clang] Fix assertion failure with malformed destructor in literal type check (PR #177918)

via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 26 02:23:23 PST 2026


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

>From 267e2d787c72f4f7832e3f4b40e4869659382cc1 Mon Sep 17 00:00:00 2001
From: nataliakokoromyti <nataliakokoromyti at gmail.com>
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 | 10 ++++++++++
 3 files changed, 11 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..7ec17e53076ca 100644
--- a/clang/test/SemaCXX/literal-type.cpp
+++ b/clang/test/SemaCXX/literal-type.cpp
@@ -176,3 +176,13 @@ 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 int foo() { S s; return 0; } // expected-error {{variable of non-literal type 'S' cannot be defined in a constexpr function before C++23}}
+#endif
+}



More information about the cfe-commits mailing list