From 7e813472a20d496c4dafb20a704932656bfc8366 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Sat, 18 Oct 2014 00:41:42 +0000 Subject: [PATCH 1/1] compiler: Don't allow tuple assignments to contain duplicate symbols. Fixes issue 8436. From-SVN: r216420 --- gcc/go/gofrontend/parse.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/gcc/go/gofrontend/parse.cc b/gcc/go/gofrontend/parse.cc index b97ada19c84..c4bcf058d8e 100644 --- a/gcc/go/gofrontend/parse.cc +++ b/gcc/go/gofrontend/parse.cc @@ -2088,6 +2088,9 @@ Parse::simple_var_decl_or_assignment(const std::string& name, Typed_identifier_list til; til.push_back(Typed_identifier(name, NULL, location)); + std::set uniq_idents; + uniq_idents.insert(name); + // We've seen one identifier. If we see a comma now, this could be // "a, *p = 1, 2". if (this->peek_token()->is_op(OPERATOR_COMMA)) @@ -2102,6 +2105,7 @@ Parse::simple_var_decl_or_assignment(const std::string& name, std::string id = token->identifier(); bool is_id_exported = token->is_identifier_exported(); Location id_location = token->location(); + std::pair::iterator, bool> ins; token = this->advance_token(); if (!token->is_op(OPERATOR_COMMA)) @@ -2109,6 +2113,10 @@ Parse::simple_var_decl_or_assignment(const std::string& name, if (token->is_op(OPERATOR_COLONEQ)) { 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()); til.push_back(Typed_identifier(id, NULL, location)); } else @@ -2119,6 +2127,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()); til.push_back(Typed_identifier(id, NULL, location)); } -- 2.30.2