aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2011-10-24 19:44:18 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2011-10-24 19:44:18 +0000
commit980889d81482ecc88280262cdd101471f8e3c511 (patch)
tree3a7c7b7ffcde861a01beb3e7d1625af06e68d738 /gcc
parentd41c3b89475f0bcb0ed03f78d7ab2d4c9f94844a (diff)
downloadgcc-980889d81482ecc88280262cdd101471f8e3c511.zip
gcc-980889d81482ecc88280262cdd101471f8e3c511.tar.gz
gcc-980889d81482ecc88280262cdd101471f8e3c511.tar.bz2
Error if naked return when result variables are shadowed.
From-SVN: r180401
Diffstat (limited to 'gcc')
-rw-r--r--gcc/go/gofrontend/parse.cc17
1 files changed, 17 insertions, 0 deletions
diff --git a/gcc/go/gofrontend/parse.cc b/gcc/go/gofrontend/parse.cc
index 8c42fa2..6f7b8f2 100644
--- a/gcc/go/gofrontend/parse.cc
+++ b/gcc/go/gofrontend/parse.cc
@@ -3839,6 +3839,23 @@ Parse::return_stat()
if (this->expression_may_start_here())
vals = this->expression_list(NULL, false);
this->gogo_->add_statement(Statement::make_return_statement(vals, location));
+
+ if (vals == NULL
+ && this->gogo_->current_function()->func_value()->results_are_named())
+ {
+ Named_object* function = this->gogo_->current_function();
+ Function::Results* results = function->func_value()->result_variables();
+ for (Function::Results::const_iterator p = results->begin();
+ p != results->end();
+ ++p)
+ {
+ Named_object* no = this->gogo_->lookup((*p)->name(), NULL);
+ go_assert(no != NULL);
+ if (!no->is_result_variable())
+ error_at(location, "%qs is shadowed during return",
+ (*p)->message_name().c_str());
+ }
+ }
}
// IfStmt = "if" [ SimpleStmt ";" ] Expression Block