compiler: disallow fallthrough in last case of switch.
authorIan Lance Taylor <ian@gcc.gnu.org>
Wed, 26 Jun 2013 22:58:03 +0000 (22:58 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Wed, 26 Jun 2013 22:58:03 +0000 (22:58 +0000)
In spec: A "fallthrough" statement may appear as the last
statement of all but the last clause of an expression switch.

From-SVN: r200440

gcc/go/gofrontend/parse.cc

index 0a67bbe40605668a6f2782417f3467b39f2e8d55..5a9feb7280bb744f15280de29e0236f7ce0cee47 100644 (file)
@@ -4523,9 +4523,12 @@ Parse::expr_case_clause(Case_clauses* clauses, bool* saw_default)
   bool is_fallthrough = false;
   if (this->peek_token()->is_keyword(KEYWORD_FALLTHROUGH))
     {
+      Location fallthrough_loc = this->location();
       is_fallthrough = true;
       if (this->advance_token()->is_op(OPERATOR_SEMICOLON))
        this->advance_token();
+      if (this->peek_token()->is_op(OPERATOR_RCURLY))
+       error_at(fallthrough_loc, _("cannot fallthrough final case in switch"));
     }
 
   if (is_default)