@@ -9905,8 +9905,11 @@ start_enum (location_t loc, struct c_enum_contents *the_enum, tree name,
if (ENUM_FIXED_UNDERLYING_TYPE_P (enumtype)
&& fixed_underlying_type == NULL_TREE)
- error_at (loc, "%<enum%> declared with but defined without "
- "fixed underlying type");
+ {
+ error_at (loc, "%<enum%> declared with but defined without "
+ "fixed underlying type");
+ ENUM_FIXED_UNDERLYING_TYPE_P (enumtype) = false;
+ }
the_enum->enum_next_value = integer_zero_node;
the_enum->enum_type = enumtype;
new file mode 100644
@@ -0,0 +1,6 @@
+/* PR c/112571. */
+/* { dg-do compile } */
+/* { dg-options "-std=c23" } */
+
+enum X : typeof (enum X { A }); /* { dg-error "declared with but defined without fixed underlying type" } */
+/* { dg-error "invalid 'enum' underlying type" "invalid" { target *-*-* } .-1 } */
new file mode 100644
@@ -0,0 +1,8 @@
+/* PR c/112571. */
+/* { dg-do compile } */
+/* { dg-options "-std=c23" } */
+
+enum h : typeof (enum h { D }) { D }; /* { dg-error "declared with but defined without fixed underlying type" } */
+/* { dg-error "invalid 'enum' underlying type" "invalid" { target *-*-* } .-1 } */
+/* { dg-error "nested redefinition" "nested" { target *-*-* } .-2 } */
+/* { dg-error "conflicting redefinition" "conflicting" { target *-*-* } .-3 } */