This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH] Allow __label__ after for/while () { (PR c++/39028)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Jason Merrill <jason at redhat dot com>, Mark Mitchell <mark at codesourcery dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Fri, 30 Jan 2009 16:48:15 +0100
- Subject: [C++ PATCH] Allow __label__ after for/while () { (PR c++/39028)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
My PR32121 patch to restrict __label__ decls right after opening {
broke the attached testcase. For for and while with brace surrounded body
cp_parser_compound_statement isn't called and parsing of the __label__s
is now done only in that function. This patch fixes this by also handling
it in cp_parser_already_scoped_statement. The only other caller
of cp_parser_statement_seq_opt, #pragma omp for error handling, doesn't
want __label__s to be parsed, as it isn't called afte ropening { brace.
Bootstrapped/regtested on x86_64-linux, ok for trunk?
2009-01-30 Jakub Jelinek <jakub@redhat.com>
PR c++/39028
* parser.c (cp_parser_already_scoped_statement): Handle __label__
declarations.
* g++.dg/ext/label12.C: New test.
--- gcc/cp/parser.c.jj 2009-01-26 15:24:39.000000000 +0100
+++ gcc/cp/parser.c 2009-01-30 13:13:01.000000000 +0100
@@ -7844,6 +7844,10 @@ cp_parser_already_scoped_statement (cp_p
/* Avoid calling cp_parser_compound_statement, so that we
don't create a new scope. Do everything else by hand. */
cp_parser_require (parser, CPP_OPEN_BRACE, "%<{%>");
+ /* 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, NULL_TREE);
cp_parser_require (parser, CPP_CLOSE_BRACE, "%<}%>");
}
--- gcc/testsuite/g++.dg/ext/label12.C.jj 2009-01-30 13:05:54.000000000 +0100
+++ gcc/testsuite/g++.dg/ext/label12.C 2009-01-30 13:08:13.000000000 +0100
@@ -0,0 +1,39 @@
+// PR c++/39028
+// { dg-do compile }
+// Origin: Stephan Springl <springl@bfw-online.de>
+
+void
+f ()
+{
+ int i;
+ for (i = 0; i < 2; i++)
+ {
+ __label__ l;
+ goto l;
+ l:;
+ }
+ while (i++ < 5)
+ {
+ __label__ l;
+ goto l;
+ l:;
+ }
+ do
+ {
+ __label__ l;
+ goto l;
+ l:;
+ }
+ while (i++ < 8);
+ if (1)
+ {
+ __label__ l;
+ goto l;
+ l:;
+ }
+ {
+ __label__ l;
+ goto l;
+ l:;
+ }
+}
Jakub