c-parser (c_parser_statement_after_labels): Move error from here...

2007-12-04  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>

	* c-parser (c_parser_statement_after_labels): Move error from here...
	(c_parser_label): ... to here. Check that the declaration is not
	actually just another label.
testsuite/
	* gcc.dg/parse-decl-after-if.c: New.
	* gcc.dg/20031223-1.c: Adjust.

From-SVN: r130606
parent 2f93f02c
2007-12-04 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
* c-parser (c_parser_statement_after_labels): Move error from here...
(c_parser_label): ... to here. Check that the declaration is not
actually just another label.
2007-12-04 Richard Guenther <rguenther@suse.de> 2007-12-04 Richard Guenther <rguenther@suse.de>
PR middle-end/34334 PR middle-end/34334
...@@ -3638,7 +3638,20 @@ c_parser_label (c_parser *parser) ...@@ -3638,7 +3638,20 @@ c_parser_label (c_parser *parser)
} }
} }
if (label) if (label)
SET_EXPR_LOCATION (label, loc1); {
SET_EXPR_LOCATION (label, loc1);
if (c_parser_next_token_starts_declspecs (parser)
&& !(c_parser_next_token_is (parser, CPP_NAME)
&& c_parser_peek_2nd_token (parser)->type == CPP_COLON))
{
error ("%Ha label can only be part of a statement and "
"a declaration is not a statement",
&c_parser_peek_token (parser)->location);
c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false,
/*nested*/ true, /*empty_ok*/ false,
/*start_attr_ok*/ true);
}
}
} }
/* Parse a statement (C90 6.6, C99 6.8). /* Parse a statement (C90 6.6, C99 6.8).
...@@ -3864,16 +3877,6 @@ c_parser_statement_after_labels (c_parser *parser) ...@@ -3864,16 +3877,6 @@ c_parser_statement_after_labels (c_parser *parser)
break; break;
default: default:
expr_stmt: expr_stmt:
if (c_parser_next_token_starts_declspecs (parser))
{
error ("%Ha label can only be part of a statement and "
"a declaration is not a statement",
&c_parser_peek_token (parser)->location);
c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false,
/*nested*/ true, /*empty_ok*/ false,
/*start_attr_ok*/ true);
return;
}
stmt = c_finish_expr_stmt (c_parser_expression_conv (parser).value); stmt = c_finish_expr_stmt (c_parser_expression_conv (parser).value);
expect_semicolon: expect_semicolon:
c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
......
2007-12-04 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
* gcc.dg/parse-decl-after-if.c: New.
* gcc.dg/20031223-1.c: Adjust.
2007-12-04 Douglas Gregor <doug.gregor@gmail.com> 2007-12-04 Douglas Gregor <doug.gregor@gmail.com>
PR c++/33509 PR c++/33509
...@@ -9,4 +9,5 @@ void f () ...@@ -9,4 +9,5 @@ void f ()
{ {
l: int; /* { dg-error "a label can only be part of a statement and a declaration is not a statement" } */ l: int; /* { dg-error "a label can only be part of a statement and a declaration is not a statement" } */
/* { dg-warning "useless type name in empty declaration" "" { target *-*-* } 10 } */ /* { dg-warning "useless type name in empty declaration" "" { target *-*-* } 10 } */
/* { dg-error "label at end of compound statement" "" { target *-*-* } 10 } */
} }
/* Parse error recovery
{ dg-do compile }
{ dg-options "-fsyntax-only" }
*/
void f(x)
{
if (x > 1)
int ret = 1; /* { dg-error "expected expression before 'int'" } */
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment