[clang] [Clang] treat fixed-underlying enum constants as the enumerated type in C23 to follow the spec (PR #172211)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 6 09:49:51 PST 2026


================
@@ -20845,10 +20847,13 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, SourceRange BraceRange,
       ECD->setInitExpr(ImplicitCastExpr::Create(
           Context, NewTy, CK_IntegralCast, ECD->getInitExpr(),
           /*base paths*/ nullptr, VK_PRValue, FPOptionsOverride()));
-    if (getLangOpts().CPlusPlus)
+    if (getLangOpts().CPlusPlus ||
+        (getLangOpts().C23 && (Enum->isFixed() || !MembersRepresentableByInt)))
       // C++ [dcl.enum]p4: Following the closing brace of an
       // enum-specifier, each enumerator has the type of its
       // enumeration.
+      // C23 6.7.2.2p15: For an enumerated type with fixed underlying type, the
----------------
AaronBallman wrote:

Same fix to the comment as above.

https://github.com/llvm/llvm-project/pull/172211


More information about the cfe-commits mailing list