The Go frontend gave an incorrect "missing return" error message for a
type switch with a case with multiple types, as in "case T1, T2:".  This
patch fixes that problem.  This patch also changes the "missing return"
error message to use the same text as the gc compiler, and reports it at
the end of the function rather than the start of the function, again to
match the gc compiler.  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline and 4.8 branch.

Ian

Index: gcc/go/gofrontend/gogo.cc
===================================================================
--- gcc/go/gofrontend/gogo.cc	(revision 201536)
+++ gcc/go/gofrontend/gogo.cc	(working copy)
@@ -3133,7 +3133,8 @@ Check_return_statements_traverse::functi
     return TRAVERSE_CONTINUE;
 
   if (func->block()->may_fall_through())
-    error_at(func->location(), "control reaches end of non-void function");
+    error_at(func->block()->end_location(),
+	     "missing return at end of function");
 
   return TRAVERSE_CONTINUE;
 }
Index: gcc/go/gofrontend/statements.cc
===================================================================
--- gcc/go/gofrontend/statements.cc	(revision 201536)
+++ gcc/go/gofrontend/statements.cc	(working copy)
@@ -4093,6 +4093,16 @@ Type_case_clauses::Type_case_clause::low
 bool
 Type_case_clauses::Type_case_clause::may_fall_through() const
 {
+  if (this->is_fallthrough_)
+    {
+      // This case means that we automatically fall through to the
+      // next case (it's used for T1 in case T1, T2:).  It does not
+      // mean that we fall through to the end of the type switch as a
+      // whole.  There is sure to be a next case and that next case
+      // will determine whether we fall through to the statements
+      // after the type switch.
+      return false;
+    }
   if (this->statements_ == NULL)
     return true;
   return this->statements_->may_fall_through();
Index: gcc/testsuite/go.test/test/fixedbugs/bug086.go
===================================================================
--- gcc/testsuite/go.test/test/fixedbugs/bug086.go	(revision 200210)
+++ gcc/testsuite/go.test/test/fixedbugs/bug086.go	(working copy)
@@ -6,12 +6,12 @@
 
 package main
 
-func f() int {	// ERROR "return|control"
+func f() int {
 	if false {
 		return 0;
 	}
 	// we should not be able to return successfully w/o a return statement
-}
+} // ERROR "return"
 
 func main() {
 	print(f(), "\n");

Reply via email to