compiler: Permit label on fallthrough statement.
authorIan Lance Taylor <ian@gcc.gnu.org>
Fri, 13 Mar 2015 20:48:15 +0000 (20:48 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Fri, 13 Mar 2015 20:48:15 +0000 (20:48 +0000)
Test case: https://go-review.googlesource.com/7523 .

From-SVN: r221428

gcc/go/gofrontend/parse.cc

index 496ab41b6e3bee2a6163e26e537d8ab5955fdd34..970e6bdd14a7c82279cd3ad833d44e3abba64629 100644 (file)
@@ -3735,6 +3735,17 @@ Parse::labeled_stmt(const std::string& label_name, Location location)
 
   if (!this->statement_may_start_here())
     {
+      if (this->peek_token()->is_keyword(KEYWORD_FALLTHROUGH))
+       {
+         // We don't treat the fallthrough keyword as a statement,
+         // because it can't appear most places where a statement is
+         // permitted, but it may have a label.  We introduce a
+         // semicolon because the caller expects to see a statement.
+         this->unget_token(Token::make_operator_token(OPERATOR_SEMICOLON,
+                                                      location));
+         return;
+       }
+
       // Mark the label as used to avoid a useless error about an
       // unused label.
       if (label != NULL)