diff options
author | Jakub Jelinek <jakub@redhat.com> | 2007-10-12 09:07:46 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2007-10-12 09:07:46 +0200 |
commit | 3d3585eb17d987e33bfb59568f5bc37809c614f6 (patch) | |
tree | 10fc781a98766416b5e32e03c79388a9a60293e1 /gcc/cp/parser.c | |
parent | fa6b27349892219438887d2d9b446ed799f8878d (diff) | |
download | gcc-3d3585eb17d987e33bfb59568f5bc37809c614f6.zip gcc-3d3585eb17d987e33bfb59568f5bc37809c614f6.tar.gz gcc-3d3585eb17d987e33bfb59568f5bc37809c614f6.tar.bz2 |
re PR c++/32121 (C++ front-end accepts invalid __label__ declarations)
PR c++/32121
* parser.c (cp_parser_compound_statement): Handle label-declarations
at the beginning of the compound statement.
(cp_parser_block_declaration): Issue diagnostics about __label__
not at the beginning of a block.
* g++.dg/ext/label4.C: Adjust error regexp.
* g++.dg/ext/label6.C: Adjust error regexp.
* g++.dg/ext/label7.C: New test.
* g++.dg/ext/label8.C: New test.
* g++.dg/ext/label9.C: New test.
From-SVN: r129253
Diffstat (limited to 'gcc/cp/parser.c')
-rw-r--r-- | gcc/cp/parser.c | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 3720b55..3fab4dc 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -6821,6 +6821,15 @@ cp_parser_expression_statement (cp_parser* parser, tree in_statement_expr) compound-statement: { statement-seq [opt] } + GNU extension: + + compound-statement: + { label-declaration-seq [opt] statement-seq [opt] } + + label-declaration-seq: + label-declaration + label-declaration-seq label-declaration + Returns a tree representing the statement. */ static tree @@ -6834,6 +6843,9 @@ cp_parser_compound_statement (cp_parser *parser, tree in_statement_expr, return error_mark_node; /* Begin the compound-statement. */ compound_stmt = begin_compound_stmt (in_try ? BCS_TRY_BLOCK : 0); + /* If the next keyword is `__label__' we have a label declaration. */ + while (cp_lexer_next_token_is_keyword (parser->lexer, RID_LABEL)) + cp_parser_label_declaration (parser); /* Parse an (optional) statement-seq. */ cp_parser_statement_seq_opt (parser, in_statement_expr); /* Finish the compound-statement. */ @@ -7711,7 +7723,6 @@ cp_parser_declaration (cp_parser* parser) block-declaration: __extension__ block-declaration - label-declaration C++0x Extension: @@ -7772,12 +7783,16 @@ cp_parser_block_declaration (cp_parser *parser, cp_parser_using_declaration (parser, /*access_declaration_p=*/false); } - /* If the next keyword is `__label__' we have a label declaration. */ + /* If the next keyword is `__label__' we have a misplaced label + declaration. */ else if (token1->keyword == RID_LABEL) { - if (statement_p) - cp_parser_commit_to_tentative_parse (parser); - cp_parser_label_declaration (parser); + cp_lexer_consume_token (parser->lexer); + error ("%<__label__%> not at the beginning of a block"); + cp_parser_skip_to_end_of_statement (parser); + /* If the next token is now a `;', consume it. */ + if (cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON)) + cp_lexer_consume_token (parser->lexer); } /* If the next token is `static_assert' we have a static assertion. */ else if (token1->keyword == RID_STATIC_ASSERT) |