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
This commit is contained in:
parent
fa6b273498
commit
3d3585eb17
8 changed files with 83 additions and 7 deletions
|
@ -1,3 +1,11 @@
|
|||
2007-10-12 Jakub Jelinek <jakub@redhat.com>
|
||||
|
||||
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.
|
||||
|
||||
2007-10-11 Paolo Carlini <pcarlini@suse.de>
|
||||
|
||||
PR c++/33461
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -1,3 +1,12 @@
|
|||
2007-10-12 Jakub Jelinek <jakub@redhat.com>
|
||||
|
||||
PR c++/32121
|
||||
* 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.
|
||||
|
||||
2007-10-11 Kenneth Zadeck <zadeck@naturalbridge.com>
|
||||
|
||||
PR middle-end/33676
|
||||
|
|
|
@ -3,4 +3,4 @@
|
|||
|
||||
// { dg-do compile }
|
||||
|
||||
__label__ *l; // { dg-error "before" }
|
||||
__label__ *l; // { dg-error "not at the beginning of" }
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
// PR c++/32108
|
||||
|
||||
__label__ L; // { dg-error "function scopes" }
|
||||
__label__ L; // { dg-error "not at the beginning" }
|
||||
|
|
12
gcc/testsuite/g++.dg/ext/label7.C
Normal file
12
gcc/testsuite/g++.dg/ext/label7.C
Normal file
|
@ -0,0 +1,12 @@
|
|||
// PR c++/32121
|
||||
// { dg-do compile }
|
||||
|
||||
int f (void)
|
||||
{
|
||||
a:;
|
||||
__label__ a; // { dg-error "not at the beginning" }
|
||||
int b;
|
||||
__label__ c; // { dg-error "not at the beginning" }
|
||||
a:; // { dg-error "duplicate label" }
|
||||
c:;
|
||||
}
|
22
gcc/testsuite/g++.dg/ext/label8.C
Normal file
22
gcc/testsuite/g++.dg/ext/label8.C
Normal file
|
@ -0,0 +1,22 @@
|
|||
// PR c++/32121
|
||||
// { dg-do compile }
|
||||
|
||||
int f (void)
|
||||
{
|
||||
__label__ a, b;
|
||||
__label__ c;
|
||||
a:;
|
||||
b:;
|
||||
c:;
|
||||
{
|
||||
__label__ d;
|
||||
d:;
|
||||
if (0)
|
||||
{
|
||||
__label__ e;
|
||||
__label__ f;
|
||||
f:;
|
||||
e:;
|
||||
}
|
||||
}
|
||||
}
|
10
gcc/testsuite/g++.dg/ext/label9.C
Normal file
10
gcc/testsuite/g++.dg/ext/label9.C
Normal file
|
@ -0,0 +1,10 @@
|
|||
// PR c++/32121
|
||||
// { dg-do compile }
|
||||
|
||||
int f (void)
|
||||
{
|
||||
while (1)
|
||||
__label__ a; // { dg-error "not at the beginning" }
|
||||
for (;;)
|
||||
__label__ b; // { dg-error "not at the beginning" }
|
||||
}
|
Loading…
Add table
Reference in a new issue