diff options
author | Joseph Myers <jsm@polyomino.org.uk> | 2004-09-24 18:22:20 +0100 |
---|---|---|
committer | Joseph Myers <jsm28@gcc.gnu.org> | 2004-09-24 18:22:20 +0100 |
commit | 085e33aa0ad674c2680e6216b7d84737b935351c (patch) | |
tree | 0df83d2241d0c2e8cf4abfc9975db885362bef6d /gcc/c-decl.c | |
parent | a2159c4c35aa1759292e9cce4ae97bbf04c5861e (diff) | |
download | gcc-085e33aa0ad674c2680e6216b7d84737b935351c.zip gcc-085e33aa0ad674c2680e6216b7d84737b935351c.tar.gz gcc-085e33aa0ad674c2680e6216b7d84737b935351c.tar.bz2 |
re PR c/17188 (struct Foo { } redefinition)
PR c/17188
* 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: r88063
Diffstat (limited to 'gcc/c-decl.c')
-rw-r--r-- | gcc/c-decl.c | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/gcc/c-decl.c b/gcc/c-decl.c index 98f1580..3a2f576 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -1145,6 +1145,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 %qD", newdecl, newdecl); + locate_old_decl (olddecl, error); + return false; + } + if (!comptypes (oldtype, newtype)) { if (TREE_CODE (olddecl) == FUNCTION_DECL @@ -4910,13 +4919,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 { @@ -5123,11 +5141,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 %qs", - IDENTIFIER_POINTER (TYPE_NAME (t))); - if (DECL_INITIAL (x)) { unsigned HOST_WIDE_INT width = tree_low_cst (DECL_INITIAL (x), 1); @@ -5330,6 +5343,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) |