@@ -4814,6 +4814,20 @@ shadow_tag_warned (const struct c_declspecs *declspecs, int warned)
warned = 1;
pending_xref_error ();
}
+ else if (declspecs->typespec_kind != ctsk_tagdef
+ && declspecs->typespec_kind != ctsk_tagfirstref
+ && declspecs->typespec_kind != ctsk_tagfirstref_attrs
+ && code == ENUMERAL_TYPE)
+ {
+ bool warned_enum = false;
+ if (warned != 1)
+ warned_enum = pedwarn (input_location, OPT_Wpedantic,
+ "empty declaration of %<enum%> type "
+ "does not redeclare tag");
+ if (warned_enum)
+ warned = 1;
+ pending_xref_error ();
+ }
else
{
pending_invalid_xref = NULL_TREE;
new file mode 100644
@@ -0,0 +1,8 @@
+/* Test for handling of tags. "enum foo;" is invalid after an existing
+ declaration (does not redeclare the tag) as well as before: bug 107164. */
+/* { dg-do compile } */
+/* { dg-options "-std=c99 -pedantic-errors" } */
+
+enum e1; /* { dg-error "ISO C forbids forward references to 'enum' types" } */
+enum e2 { E };
+enum e2; /* { dg-error "empty declaration of 'enum' type does not redeclare tag" } */
new file mode 100644
@@ -0,0 +1,8 @@
+/* Test for handling of tags. "enum foo;" is invalid after an existing
+ declaration (does not redeclare the tag) as well as before: bug 107164. */
+/* { dg-do compile } */
+/* { dg-options "-std=c99 -pedantic" } */
+
+enum e1; /* { dg-warning "ISO C forbids forward references to 'enum' types" } */
+enum e2 { E };
+enum e2; /* { dg-warning "empty declaration of 'enum' type does not redeclare tag" } */
new file mode 100644
@@ -0,0 +1,9 @@
+/* Test for handling of tags. "enum foo;" is invalid after an existing
+ declaration (does not redeclare the tag) as well as before: bug 107164.
+ Test this is not diagnosed without -pedantic. */
+/* { dg-do compile } */
+/* { dg-options "-std=c99" } */
+
+enum e1;
+enum e2 { E };
+enum e2;