From: Ian Lance Taylor Date: Fri, 22 Jul 2016 00:21:51 +0000 (+0000) Subject: compiler: fix check for duplicate declaration X-Git-Tag: upstream/12.2.0~45729 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4114e6b1fe8bb10a42ce56263ad42cba98138254;p=platform%2Fupstream%2Fgcc.git compiler: fix check for duplicate declaration The compiler check that issued a duplicate declaration error for a, a, a := 1, 2, 3 was incorrectly issuing an error for a, a, a = 1, 2, 3 While this is not particularly useful, it is valid Go. Test is https://golang.org/cl/25143. Reviewed-on: https://go-review.googlesource.com/25144 From-SVN: r238618 --- diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index 7798423..7e8d9d4 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -5ea5c078829ae83bccb598772fff7c1a04e23e65 +4c88f31a83ca28963d29d6dc9fcdb2e9b093610c The first line of this file holds the git revision number of the last merge done from the gofrontend repository. diff --git a/gcc/go/gofrontend/parse.cc b/gcc/go/gofrontend/parse.cc index c96ae1d..d9f2040 100644 --- a/gcc/go/gofrontend/parse.cc +++ b/gcc/go/gofrontend/parse.cc @@ -2106,6 +2106,8 @@ Parse::simple_var_decl_or_assignment(const std::string& name, std::set uniq_idents; uniq_idents.insert(name); + std::string dup_name; + Location dup_loc; // We've seen one identifier. If we see a comma now, this could be // "a, *p = 1, 2". @@ -2145,8 +2147,10 @@ Parse::simple_var_decl_or_assignment(const std::string& name, id = this->gogo_->pack_hidden_name(id, is_id_exported); ins = uniq_idents.insert(id); if (!ins.second && !Gogo::is_sink_name(id)) - error_at(id_location, "multiple assignments to %s", - Gogo::message_name(id).c_str()); + { + dup_name = Gogo::message_name(id); + dup_loc = id_location; + } til.push_back(Typed_identifier(id, NULL, location)); } @@ -2182,6 +2186,9 @@ Parse::simple_var_decl_or_assignment(const std::string& name, go_assert(this->peek_token()->is_op(OPERATOR_COLONEQ)); const Token* token = this->advance_token(); + if (!dup_name.empty()) + error_at(dup_loc, "multiple assignments to %s", dup_name.c_str()); + if (p_range_clause != NULL && token->is_keyword(KEYWORD_RANGE)) { this->range_clause_decl(&til, p_range_clause);