From cb96a11382d55dc271985781aadc6945bd4faed2 Mon Sep 17 00:00:00 2001 From: ian Date: Mon, 3 Aug 2015 19:55:00 +0000 Subject: [PATCH] compiler: Don't allow multiple function declarations. Fixes golang/go#11573. Reviewed-on: https://go-review.googlesource.com/12508 git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@226529 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/go/gofrontend/MERGE | 2 +- gcc/go/gofrontend/gogo.cc | 10 ++-------- gcc/go/gofrontend/parse.cc | 5 ++++- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index e3a971a8e61..56ae88e5aad 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -2b1a79c6395991fc4e60e20312ff44065fdb816b +7a6089333f4ab10449f9140c4639cfe741abcb25 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/gogo.cc b/gcc/go/gofrontend/gogo.cc index 52bec3dc6dd..9a5dd57cdb5 100644 --- a/gcc/go/gofrontend/gogo.cc +++ b/gcc/go/gofrontend/gogo.cc @@ -7408,16 +7408,10 @@ Bindings::new_definition(Named_object* old_object, Named_object* new_object) case Named_object::NAMED_OBJECT_FUNC_DECLARATION: { - Function_type* old_type = old_object->func_declaration_value()->type(); - if (new_object->is_function_declaration()) - { - Function_type* new_type = - new_object->func_declaration_value()->type(); - if (old_type->is_valid_redeclaration(new_type, &reason)) - return old_object; - } if (new_object->is_function()) { + Function_type* old_type = + old_object->func_declaration_value()->type(); Function_type* new_type = new_object->func_value()->type(); if (old_type->is_valid_redeclaration(new_type, &reason)) { diff --git a/gcc/go/gofrontend/parse.cc b/gcc/go/gofrontend/parse.cc index b7a0c3973a4..7f7eba489c7 100644 --- a/gcc/go/gofrontend/parse.cc +++ b/gcc/go/gofrontend/parse.cc @@ -2231,9 +2231,11 @@ Parse::function_decl(bool saw_nointerface) std::string extern_name = this->lex_->extern_name(); const Token* token = this->advance_token(); + bool expected_receiver = false; Typed_identifier* rec = NULL; if (token->is_op(OPERATOR_LPAREN)) { + expected_receiver = true; rec = this->receiver(); token = this->peek_token(); } @@ -2304,7 +2306,8 @@ Parse::function_decl(bool saw_nointerface) { if (named_object == NULL && !Gogo::is_sink_name(name)) { - if (fntype == NULL) + if (fntype == NULL + || (expected_receiver && rec == NULL)) this->gogo_->add_erroneous_name(name); else { -- 2.11.4.GIT