]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/32121 (C++ front-end accepts invalid __label__ declarations)
authorJakub Jelinek <jakub@redhat.com>
Fri, 12 Oct 2007 07:07:46 +0000 (09:07 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 12 Oct 2007 07:07:46 +0000 (09:07 +0200)
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

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ext/label4.C
gcc/testsuite/g++.dg/ext/label6.C
gcc/testsuite/g++.dg/ext/label7.C [new file with mode: 0644]
gcc/testsuite/g++.dg/ext/label8.C [new file with mode: 0644]
gcc/testsuite/g++.dg/ext/label9.C [new file with mode: 0644]

index 1aeacba8b96cbc4da4073d94bd6744a1fb3e71dc..faea90d1e3c0ee4d69a84eee5b1a436f0becaa57 100644 (file)
@@ -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
index 3720b5567a5c708c1677ac45bcf21dc6b2852e0f..3fab4dc8a05ebbd925ccf4b1e3f1b2c4284cf81d 100644 (file)
@@ -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)
index 3041b96d5587ad984bcae8d85361b50b3013e0f2..7434c1e36c971a811d54198fbeea56baf2168567 100644 (file)
@@ -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
index 80b50a799815fdfc1a5a76dc836541a895ee3550..93f140f3429f1fc416d63f5e585e960869ae5e57 100644 (file)
@@ -3,4 +3,4 @@
 
 // { dg-do compile }
 
-__label__ *l;  // { dg-error "before" }
+__label__ *l;  // { dg-error "not at the beginning of" }
index d026777eb9f688c3ff566886d60ad0ac52e9a816..e4b0c37c2d10ec3386025ca6b8ca4e1922c9f31e 100644 (file)
@@ -1,3 +1,3 @@
 // PR c++/32108
 
-__label__ L; // { dg-error "function scopes" }
+__label__ L; // { dg-error "not at the beginning" }
diff --git a/gcc/testsuite/g++.dg/ext/label7.C b/gcc/testsuite/g++.dg/ext/label7.C
new file mode 100644 (file)
index 0000000..e92dccf
--- /dev/null
@@ -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:;
+}
diff --git a/gcc/testsuite/g++.dg/ext/label8.C b/gcc/testsuite/g++.dg/ext/label8.C
new file mode 100644 (file)
index 0000000..1f6175d
--- /dev/null
@@ -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:;
+      }
+  }
+}
diff --git a/gcc/testsuite/g++.dg/ext/label9.C b/gcc/testsuite/g++.dg/ext/label9.C
new file mode 100644 (file)
index 0000000..81b385f
--- /dev/null
@@ -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" }
+}