Patchwork Go patch committed: Disallow fallthrough at end of switch

login
register
mail settings
Submitter Ian Taylor
Date June 26, 2013, 10:58 p.m.
Message ID <mcrfvw4lbso.fsf@iant-glaptop.roam.corp.google.com>
Download mbox | patch
Permalink /patch/254913/
State New
Headers show

Comments

Ian Taylor - June 26, 2013, 10:58 p.m.
In Go 1 the fallthrough statement is no longer permitted in the last
case of a switch, as there is no code to which to fall through.  This
patch from Rémy Oudompheng implements this restriction in gccgo.
Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline and 4.8 branch.

Ian

Patch

diff -r 133fcbfa33c6 go/parse.cc
--- a/go/parse.cc	Wed Jun 26 15:31:30 2013 -0700
+++ b/go/parse.cc	Wed Jun 26 15:44:23 2013 -0700
@@ -4523,9 +4523,12 @@ 
   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)