diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2018-02-05 01:53:23 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2018-02-05 01:53:23 +0000 |
commit | 33cdac3baa9e0c8da598d5124ac9196be30a3ccb (patch) | |
tree | c272b5d4ac7f6b0339f877949b0f1eb2c773ba1a /gcc/go | |
parent | 964c809fb28f2bbb5b7c35d7951911abff242b94 (diff) | |
download | gcc-33cdac3baa9e0c8da598d5124ac9196be30a3ccb.zip gcc-33cdac3baa9e0c8da598d5124ac9196be30a3ccb.tar.gz gcc-33cdac3baa9e0c8da598d5124ac9196be30a3ccb.tar.bz2 |
compiler: permit empty statements after fallthrough
The language spec permits empty statements after a fallthrough
statement, so implement that. Also give a better error message when a
fallthrough statement is in the wrong place. The test case for this
is in the master repository, test/fixedbugs/issue14540.go, just not
yet in the gccgo repository.
Fixes golang/go#14538
Reviewed-on: https://go-review.googlesource.com/91855
From-SVN: r257378
Diffstat (limited to 'gcc/go')
-rw-r--r-- | gcc/go/gofrontend/MERGE | 2 | ||||
-rw-r--r-- | gcc/go/gofrontend/parse.cc | 19 |
2 files changed, 18 insertions, 3 deletions
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index 575756e..c0f977a 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -5031f878a761bf83f5f96710d62f83e2dc5ecf04 +d9f33a479f8012f7495d197e4b7417cba4d477fa The first line of this file holds the git revision number of the last merge done from the gofrontend repository. diff --git a/gcc/go/gofrontend/parse.cc b/gcc/go/gofrontend/parse.cc index 9700cc3..cc3791b 100644 --- a/gcc/go/gofrontend/parse.cc +++ b/gcc/go/gofrontend/parse.cc @@ -4667,11 +4667,26 @@ Parse::expr_case_clause(Case_clauses* clauses, bool* saw_default) { Location fallthrough_loc = this->location(); is_fallthrough = true; - if (this->advance_token()->is_op(OPERATOR_SEMICOLON)) - this->advance_token(); + while (this->advance_token()->is_op(OPERATOR_SEMICOLON)) + ; if (this->peek_token()->is_op(OPERATOR_RCURLY)) go_error_at(fallthrough_loc, _("cannot fallthrough final case in switch")); + else if (!this->peek_token()->is_keyword(KEYWORD_CASE) + && !this->peek_token()->is_keyword(KEYWORD_DEFAULT)) + { + go_error_at(fallthrough_loc, "fallthrough statement out of place"); + while (!this->peek_token()->is_keyword(KEYWORD_CASE) + && !this->peek_token()->is_keyword(KEYWORD_DEFAULT) + && !this->peek_token()->is_op(OPERATOR_RCURLY) + && !this->peek_token()->is_eof()) + { + if (this->statement_may_start_here()) + this->statement_list(); + else + this->advance_token(); + } + } } if (is_default) |