===================================================================
@@ -0,0 +1,16 @@
+/* Test diagnostics for duplicate field names involving anonymous
+ struct or union as first field. PR 46889. */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+struct foo {
+ union {
+ struct {
+ unsigned long time_stamp;
+ };
+ struct {
+ int *page;
+ };
+ };
+ int *page; /* { dg-error "duplicate member" } */
+};
===================================================================
@@ -6805,11 +6805,9 @@ detect_field_duplicates (tree fieldlist)
/* First, see if there are more than "a few" fields.
This is trivially true if there are zero or one fields. */
- if (!fieldlist)
- return;
- x = DECL_CHAIN (fieldlist);
- if (!x)
+ if (!fieldlist || !DECL_CHAIN (fieldlist))
return;
+ x = fieldlist;
do {
timeout--;
if (DECL_NAME (x) == NULL_TREE