]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c/17188 (struct Foo { } redefinition)
authorJoseph Myers <joseph@codesourcery.com>
Thu, 28 Jul 2005 23:01:29 +0000 (00:01 +0100)
committerJoseph Myers <jsm28@gcc.gnu.org>
Thu, 28 Jul 2005 23:01:29 +0000 (00:01 +0100)
PR c/17188
PR c/21899
* c-decl.c (diagnose_mismatched_decls): Check for duplicate
declarations of enumerators.
(start_struct): Check TYPE_SIZE rather than TYPE_FIELDS to check
for redefinition.  Check for nested redefinition.
(finish_struct): Don't check for nested redefinition.
(start_enum): Check for nested redefinition.

testsuite:
* gcc.dg/nested-redef-1.c, gcc.dg/pr17188-1.c: New tests.
* gcc.dg/decl-3.c: Adjust expected message.

From-SVN: r102526

gcc/ChangeLog
gcc/c-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/decl-3.c
gcc/testsuite/gcc.dg/nested-redef-1.c
gcc/testsuite/gcc.dg/pr17188-1.c

index c0b6b05577fdadba53fa8e681270212b985112bf..dbae8f32256f986006a2ddaf174fb0aadc8bfec7 100644 (file)
@@ -1,3 +1,14 @@
+2005-07-28  Joseph S. Myers  <joseph@codesourcery.com>
+
+       PR c/17188
+       PR c/21899
+       * c-decl.c (diagnose_mismatched_decls): Check for duplicate
+       declarations of enumerators.
+       (start_struct): Check TYPE_SIZE rather than TYPE_FIELDS to check
+       for redefinition.  Check for nested redefinition.
+       (finish_struct): Don't check for nested redefinition.
+       (start_enum): Check for nested redefinition.
+
 2005-07-28  Joseph S. Myers  <joseph@codesourcery.com>
 
        PR c/21873
index 8d717733ddc3a630705cb8ccc078145ea36dec0b..4eca4f26dc7e9c74d50f73b4446d61be1c653430 100644 (file)
@@ -955,6 +955,15 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl,
       return false;
     }
 
+  /* Enumerators have no linkage, so may only be declared once in a
+     given scope.  */
+  if (TREE_CODE (olddecl) == CONST_DECL)
+    {
+      error ("%Jredeclaration of enumerator `%D'", newdecl, newdecl);
+      locate_old_decl (olddecl, error);
+      return false;
+    }
+
   if (!comptypes (oldtype, newtype, COMPARE_STRICT))
     {
       if (TREE_CODE (olddecl) == FUNCTION_DECL
@@ -4779,13 +4788,22 @@ start_struct (enum tree_code code, tree name)
     ref = lookup_tag (code, name, 1);
   if (ref && TREE_CODE (ref) == code)
     {
-      if (TYPE_FIELDS (ref))
+      if (TYPE_SIZE (ref))
         {
          if (code == UNION_TYPE)
            error ("redefinition of `union %s'", IDENTIFIER_POINTER (name));
           else
            error ("redefinition of `struct %s'", IDENTIFIER_POINTER (name));
        }
+      else if (C_TYPE_BEING_DEFINED (ref))
+       {
+         if (code == UNION_TYPE)
+           error ("nested redefinition of `union %s'",
+                  IDENTIFIER_POINTER (name));
+          else
+           error ("nested redefinition of `struct %s'",
+                  IDENTIFIER_POINTER (name));
+       }
     }
   else
     {
@@ -5000,11 +5018,6 @@ finish_struct (tree t, tree fieldlist, tree attributes)
       if (C_DECL_VARIABLE_SIZE (x))
        C_TYPE_VARIABLE_SIZE (t) = 1;
 
-      /* Detect invalid nested redefinition.  */
-      if (TREE_TYPE (x) == t)
-       error ("nested redefinition of `%s'",
-              IDENTIFIER_POINTER (TYPE_NAME (t)));
-
       if (DECL_INITIAL (x))
        {
          unsigned HOST_WIDE_INT width = tree_low_cst (DECL_INITIAL (x), 1);
@@ -5202,6 +5215,9 @@ start_enum (tree name)
       pushtag (name, enumtype);
     }
 
+  if (C_TYPE_BEING_DEFINED (enumtype))
+    error ("nested redefinition of `enum %s'", IDENTIFIER_POINTER (name));
+
   C_TYPE_BEING_DEFINED (enumtype) = 1;
 
   if (TYPE_VALUES (enumtype) != 0)
index b1df1c2a64101757c25606913f328be5919114a4..6612dedf20c16db697634fb1494f8f5e5c2df34f 100644 (file)
@@ -1,3 +1,10 @@
+2005-07-28  Joseph S. Myers  <joseph@codesourcery.com>
+
+       PR c/17188
+       PR c/21899
+       * gcc.dg/nested-redef-1.c, gcc.dg/pr17188-1.c: New tests.
+       * gcc.dg/decl-3.c: Adjust expected message.
+
 2005-07-28  Joseph S. Myers  <joseph@codesourcery.com>
 
        PR c/21873
index 2bfac89c1360baca44db3cd01de389a1551b2b09..5bbe19cd2248b56508a698b844c41b90ba27651f 100644 (file)
@@ -2,4 +2,4 @@
 /* { dg-do compile } */
 
 enum { CODES }; /* { dg-error "previous definition" } */
-enum { CODES }; /* { dg-error "conflicting types" } */
+enum { CODES }; /* { dg-error "conflicting types|redeclaration of enumerator" } */
index 34b92d8f571df29cf58c798eb7303375c07a4623..0aeda61451f86f454d5117619b47e69fa3cf58ba 100644 (file)
@@ -4,21 +4,21 @@
 /* { dg-options "" } */
 
 struct s0 {
-  struct s0 { int a; } x; /* { dg-error "error: nested redefinition of 'struct s0'" } */
+  struct s0 { int a; } x; /* { dg-error "error: nested redefinition of `struct s0'" } */
 };
 
 struct s1 {
-  const struct s1 { int b; } x; /* { dg-error "error: nested redefinition of 'struct s1'" } */
+  const struct s1 { int b; } x; /* { dg-error "error: nested redefinition of `struct s1'" } */
 };
 
 struct s2 {
-  struct s2 { int c; } *x; /* { dg-error "error: nested redefinition of 'struct s2'" } */
+  struct s2 { int c; } *x; /* { dg-error "error: nested redefinition of `struct s2'" } */
 };
 
 struct s3 {
   struct s4 {
     struct s5 {
-      struct s3 { int a; } **x; /* { dg-error "error: nested redefinition of 'struct s3'" } */
+      struct s3 { int a; } **x; /* { dg-error "error: nested redefinition of `struct s3'" } */
     } y;
   } z;
 };
@@ -27,15 +27,15 @@ struct s6;
 struct s6 { struct s6 *p; };
 
 union u0 {
-  union u0 { int c; } *x; /* { dg-error "error: nested redefinition of 'union u0'" } */
+  union u0 { int c; } *x; /* { dg-error "error: nested redefinition of `union u0'" } */
 };
 
 enum e0 {
-  E0 = sizeof(enum e0 { E1 }) /* { dg-error "error: nested redefinition of 'enum e0'" } */
+  E0 = sizeof(enum e0 { E1 }) /* { dg-error "error: nested redefinition of `enum e0'" } */
 };
 
 enum e1 {
-  E2 = sizeof(enum e2 { E2 }), /* { dg-error "error: redeclaration of enumerator 'E2'" } */
+  E2 = sizeof(enum e2 { E2 }), /* { dg-error "error: redeclaration of enumerator `E2'" } */
   /* { dg-error "previous definition" "previous E2" { target *-*-* } 38 } */
   E3
 };
index 634e60c036307cda89ebcbf76869aef8568db6af..86b7ff3b43c70d0133180e30ae836af3f7f1da25 100644 (file)
@@ -7,19 +7,19 @@
 
 struct s0 { };
 struct s0;
-struct s0 { }; /* { dg-error "error: redefinition of 'struct s0'" } */
+struct s0 { }; /* { dg-error "error: redefinition of `struct s0'" } */
 
 struct s1 { };
-struct s1 { }; /* { dg-error "error: redefinition of 'struct s1'" } */
+struct s1 { }; /* { dg-error "error: redefinition of `struct s1'" } */
 
 struct s2 { int a : 1; };
-struct s2 { int a : 1; }; /* { dg-error "error: redefinition of 'struct s2'" } */
+struct s2 { int a : 1; }; /* { dg-error "error: redefinition of `struct s2'" } */
 
 struct s3 { };
-struct s3 { int a : 1; }; /* { dg-error "error: redefinition of 'struct s3'" } */
+struct s3 { int a : 1; }; /* { dg-error "error: redefinition of `struct s3'" } */
 
 struct s4 { int a : 1; };
-struct s4 { }; /* { dg-error "error: redefinition of 'struct s4'" } */
+struct s4 { }; /* { dg-error "error: redefinition of `struct s4'" } */
 
 struct s5 { int a : 1; };
 struct s5;