https://github.com/a-tarasyuk created https://github.com/llvm/llvm-project/pull/177984
Fixes #177943 --- This patch addresses cases where `__underlying_type` is used with enum redeclarations. The previously added assertion (https://github.com/llvm/llvm-project/pull/155900) treated a missing `int` on the referenced `EnumDecl` as an indicator of a _demoted definition_, while this condition can also occur for redeclarations. >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] [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)){ }, +}; +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
