Fix cp_error047.
authorChristoph Mallon <christoph.mallon@gmx.de>
Fri, 15 Aug 2008 17:59:53 +0000 (17:59 +0000)
committerChristoph Mallon <christoph.mallon@gmx.de>
Fri, 15 Aug 2008 17:59:53 +0000 (17:59 +0000)
[r21204]

parser.c

index 4ad7072..8e2cf3f 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -2550,10 +2550,21 @@ static declaration_t *parse_compound_type_specifier(bool is_struct)
                symbol = token.v.symbol;
                next_token();
 
-               if (is_struct) {
-                       declaration = get_declaration(symbol, NAMESPACE_STRUCT);
-               } else {
-                       declaration = get_declaration(symbol, NAMESPACE_UNION);
+               namespace_t const namespc =
+                       is_struct ? NAMESPACE_STRUCT : NAMESPACE_UNION;
+               declaration = get_declaration(symbol, namespc);
+               if (declaration != NULL) {
+                       if (declaration->parent_scope != scope &&
+                           (token.type == '{' || token.type == ';')) {
+                               declaration = NULL;
+                       } else if (declaration->init.complete &&
+                                  token.type == '{') {
+                               assert(symbol != NULL);
+                               errorf(HERE, "multiple definitions of '%s %Y' (previous definition at %P)",
+                                      is_struct ? "struct" : "union", symbol,
+                                      &declaration->source_position);
+                               declaration->scope.declarations = NULL;
+                       }
                }
        } else if (token.type != '{') {
                if (is_struct) {
@@ -2581,13 +2592,6 @@ static declaration_t *parse_compound_type_specifier(bool is_struct)
        }
 
        if (token.type == '{') {
-               if (declaration->init.complete) {
-                       assert(symbol != NULL);
-                       errorf(HERE, "multiple definitions of '%s %Y' (previous definition at %P)",
-                              is_struct ? "struct" : "union", symbol,
-                              &declaration->source_position);
-                       declaration->scope.declarations = NULL;
-               }
                declaration->init.complete = true;
 
                parse_compound_type_entries(declaration);