From: Christoph Mallon Date: Fri, 15 Aug 2008 17:59:53 +0000 (+0000) Subject: Fix cp_error047. X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=518c4f53492883ff62a273e8eef1c2a3f1ef2657;p=cparser Fix cp_error047. [r21204] --- diff --git a/parser.c b/parser.c index 4ad7072..8e2cf3f 100644 --- 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);