diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2018-02-12 19:29:52 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2018-02-12 19:29:52 +0000 |
commit | 52eb4ab4092228369cea5d7ca2717d32cc666c5c (patch) | |
tree | 48902ea09d6ebb6b6a26f1aa463e3e48e00381a0 /gcc | |
parent | 86ff185365dbc40b64f907be9e2f35d756776e20 (diff) | |
download | gcc-52eb4ab4092228369cea5d7ca2717d32cc666c5c.zip gcc-52eb4ab4092228369cea5d7ca2717d32cc666c5c.tar.gz gcc-52eb4ab4092228369cea5d7ca2717d32cc666c5c.tar.bz2 |
compiler: error on func declaration/definition
Long long long ago Go permitted writing
func F()
in one file and writing
func F() {}
in another file. This was removed from the language, and that is now
considered to be a multiple definition error. Gccgo never caught up
to that, and it has been permitting this invalid code for some time.
Stop permitting it, so that we give correct errors. Since we've
supported it for a long time, the compiler uses it in a couple of
cases: it predeclares the hash/equal methods if it decides to create
them while compiling another function, and it predeclares main.main as
a mechanism for getting the right warning if a program uses the wrong
signature for main. For simplicity, keep those existing uses.
This required a few minor changes in libgo which were relying,
unnecessarily, on the current behavior.
Reviewed-on: https://go-review.googlesource.com/93083
From-SVN: r257600
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/go/gofrontend/MERGE | 2 | ||||
-rw-r--r-- | gcc/go/gofrontend/gogo.cc | 36 |
2 files changed, 18 insertions, 20 deletions
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index e8a036f..ea7ae4b 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -cebdbf3f293f5b0f3120c009c47da0ceadc113cb +7998e29eec43ede1cee925d87eef0b09da67d90b 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 11ac338..0eac199 100644 --- a/gcc/go/gofrontend/gogo.cc +++ b/gcc/go/gofrontend/gogo.cc @@ -7762,33 +7762,29 @@ Bindings::new_definition(Named_object* old_object, Named_object* new_object) go_unreachable(); case Named_object::NAMED_OBJECT_FUNC: - if (new_object->is_function_declaration()) - { - if (!new_object->func_declaration_value()->asm_name().empty()) - go_error_at(Linemap::unknown_location(), - ("sorry, not implemented: " - "__asm__ for function definitions")); - Function_type* old_type = old_object->func_value()->type(); - Function_type* new_type = - new_object->func_declaration_value()->type(); - if (old_type->is_valid_redeclaration(new_type, &reason)) - return old_object; - } break; case Named_object::NAMED_OBJECT_FUNC_DECLARATION: { - if (new_object->is_function()) + // We declare the hash and equality functions before defining + // them, because we sometimes see that we need the declaration + // while we are in the middle of a different function. We + // declare the main function before the user defines it, to + // give better error messages. + if (new_object->is_function() + && ((Linemap::is_predeclared_location(old_object->location()) + && Linemap::is_predeclared_location(new_object->location())) + || (Gogo::unpack_hidden_name(old_object->name()) == "main" + && Linemap::is_unknown_location(old_object->location())))) { 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)) { - if (!old_object->func_declaration_value()->asm_name().empty()) - go_error_at(Linemap::unknown_location(), - ("sorry, not implemented: " - "__asm__ for function definitions")); + Function_declaration* fd = + old_object->func_declaration_value(); + go_assert(fd->asm_name().empty()); old_object->set_function_value(new_object->func_value()); this->named_objects_.push_back(old_object); return old_object; @@ -7810,8 +7806,10 @@ Bindings::new_definition(Named_object* old_object, Named_object* new_object) old_object->set_is_redefinition(); new_object->set_is_redefinition(); - go_inform(old_object->location(), "previous definition of %qs was here", - n.c_str()); + if (!Linemap::is_unknown_location(old_object->location()) + && !Linemap::is_predeclared_location(old_object->location())) + go_inform(old_object->location(), "previous definition of %qs was here", + n.c_str()); return old_object; } |