https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/177984

>From 8aff3bd5bf0d2d054924e5255bc58da5086476b7 Mon Sep 17 00:00:00 2001
From: Oleksandr Tarasiuk <[email protected]>
Date: Mon, 26 Jan 2026 17:40:45 +0200
Subject: [PATCH 1/2] [Clang] avoid assertion in __underlying_type for enum
 redeclarations

---
 clang/docs/ReleaseNotes.rst            | 1 +
 clang/lib/Sema/SemaType.cpp            | 1 -
 clang/test/SemaCXX/underlying_type.cpp | 9 +++++++++
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d03211a200a29..1f7fc000897a2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -175,6 +175,7 @@ Bug Fixes in This Version
 - Fixed a failed assertion in the preprocessor when ``__has_embed`` parameters 
are missing parentheses. (#GH175088)
 
 - Fix lifetime extension of temporaries in for-range-initializers in 
templates. (#GH165182)
+- Fixes an assertion failure when evaluating ``__underlying_type`` on enum 
redeclarations. (#GH177943)
 
 Bug Fixes to Compiler Builtins
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 91d36f0502d85..e941da7eeba98 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -9891,7 +9891,6 @@ static QualType GetEnumUnderlyingType(Sema &S, QualType 
BaseType,
     // This is an enum without a fixed underlying type which we skipped parsing
     // the body because we saw its definition previously in another module.
     // Use the definition's integer type in that case.
-    assert(ED->isThisDeclarationADemotedDefinition());
     Underlying = ED->getDefinition()->getIntegerType();
     assert(!Underlying.isNull());
   }
diff --git a/clang/test/SemaCXX/underlying_type.cpp 
b/clang/test/SemaCXX/underlying_type.cpp
index 6e7a53661912a..f33843ba687bb 100644
--- a/clang/test/SemaCXX/underlying_type.cpp
+++ b/clang/test/SemaCXX/underlying_type.cpp
@@ -76,3 +76,12 @@ template <typename T>
 __underlying_type(T) ft();
 auto x = &ft<E>;
 }
+
+namespace GH177943 {
+enum E {};
+enum E;
+
+enum {
+  a = (__underlying_type(E)){ },
+};
+}

>From aafe852634a28bdb3dc118a23ae415df0a9a0c5d Mon Sep 17 00:00:00 2001
From: Oleksandr Tarasiuk <[email protected]>
Date: Mon, 26 Jan 2026 18:36:51 +0200
Subject: [PATCH 2/2] remove redundant comment

---
 clang/lib/Sema/SemaType.cpp | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index e941da7eeba98..fa4dcdd9e1422 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -9888,9 +9888,6 @@ static QualType GetEnumUnderlyingType(Sema &S, QualType 
BaseType,
 
   QualType Underlying = ED->getIntegerType();
   if (Underlying.isNull()) {
-    // This is an enum without a fixed underlying type which we skipped parsing
-    // the body because we saw its definition previously in another module.
-    // Use the definition's integer type in that case.
     Underlying = ED->getDefinition()->getIntegerType();
     assert(!Underlying.isNull());
   }

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

Reply via email to