summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2013-12-12 21:35:02 +0000
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2013-12-12 21:35:02 +0000
commit67d385b18014f7aa1734ab340963e4de64275b1a (patch)
tree2444aad3c6eeed45b576c7b0b86bf2ee87d2b21d
parentdb8b0a13204419b21542718040475408358886ae (diff)
downloadgcc-67d385b18014f7aa1734ab340963e4de64275b1a.tar.gz
compiler: Better error messages for { on line after if/for/switch.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@205944 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/go/gofrontend/parse.cc25
1 files changed, 22 insertions, 3 deletions
diff --git a/gcc/go/gofrontend/parse.cc b/gcc/go/gofrontend/parse.cc
index 6e56f835699..7614e6fc795 100644
--- a/gcc/go/gofrontend/parse.cc
+++ b/gcc/go/gofrontend/parse.cc
@@ -4287,6 +4287,16 @@ Parse::if_stat()
cond = this->expression(PRECEDENCE_NORMAL, false, false, NULL, NULL);
}
+ // Check for the easy error of a newline before starting the block.
+ if (this->peek_token()->is_op(OPERATOR_SEMICOLON))
+ {
+ Location semi_loc = this->location();
+ if (this->advance_token()->is_op(OPERATOR_LCURLY))
+ error_at(semi_loc, "missing %<{%> after if clause");
+ // Otherwise we will get an error when we call this->block
+ // below.
+ }
+
this->gogo_->start_block(this->location());
Location end_loc = this->block();
Block* then_block = this->gogo_->finish_block(end_loc);
@@ -4431,7 +4441,7 @@ Parse::switch_stat(Label* label)
Location token_loc = this->location();
if (this->peek_token()->is_op(OPERATOR_SEMICOLON)
&& this->advance_token()->is_op(OPERATOR_LCURLY))
- error_at(token_loc, "unexpected semicolon or newline before %<{%>");
+ error_at(token_loc, "missing %<{%> after switch clause");
else if (this->peek_token()->is_op(OPERATOR_COLONEQ))
{
error_at(token_loc, "invalid variable name");
@@ -5158,6 +5168,16 @@ Parse::for_stat(Label* label)
}
}
+ // Check for the easy error of a newline before starting the block.
+ if (this->peek_token()->is_op(OPERATOR_SEMICOLON))
+ {
+ Location semi_loc = this->location();
+ if (this->advance_token()->is_op(OPERATOR_LCURLY))
+ error_at(semi_loc, "missing %<{%> after for clause");
+ // Otherwise we will get an error when we call this->block
+ // below.
+ }
+
// Build the For_statement and note that it is the current target
// for break and continue statements.
@@ -5224,8 +5244,7 @@ Parse::for_clause(Expression** cond, Block** post)
*cond = NULL;
else if (this->peek_token()->is_op(OPERATOR_LCURLY))
{
- error_at(this->location(),
- "unexpected semicolon or newline before %<{%>");
+ error_at(this->location(), "missing %<{%> after for clause");
*cond = NULL;
*post = NULL;
return;