OSDN Git Service

2007-11-03 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
authormanu <manu@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 3 Nov 2007 19:41:20 +0000 (19:41 +0000)
committermanu <manu@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 3 Nov 2007 19:41:20 +0000 (19:41 +0000)
PR c/29062
* c-parser.c (c_parser_statement_after_labels): Error if a
declaration is parsed after a label.
testsuite/
* gcc.dg/20031223-1.c: Adjust error output.
* gcc.dg/parse-decl-after-label.c: New.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@129873 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/c-parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/20031223-1.c
gcc/testsuite/gcc.dg/parse-decl-after-label.c [new file with mode: 0644]

index c78cf43..0ec6736 100644 (file)
@@ -1,3 +1,9 @@
+2007-11-03  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
+
+       PR c/29062
+       * c-parser.c (c_parser_statement_after_labels): Error if a
+       declaration is parsed after a label.
+       
 2007-11-03  Daniel Jacobowitz  <dan@codesourcery.com>
 
        PR debug/33921
index 2914826..322f600 100644 (file)
@@ -3811,6 +3811,14 @@ c_parser_statement_after_labels (c_parser *parser)
       break;
     default:
     expr_stmt:
+      if (c_parser_next_token_starts_declspecs (parser)) 
+       {
+         error ("a label can only be part of a statement and a declaration is not a statement");
+         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);
     expect_semicolon:
       c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
index 0fec43d..4634c63 100644 (file)
@@ -1,3 +1,9 @@
+2007-11-03  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
+
+       PR c/29062
+       * gcc.dg/20031223-1.c: Adjust error output.
+       * gcc.dg/parse-decl-after-label.c: New.
+       
 2007-11-03  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
 
        PR libfortran/24685
index a022bf2..d44a9cd 100644 (file)
@@ -7,5 +7,6 @@
 
 void f ()
 {
- l: int; /* { dg-error "" } */
+ 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 } */
 }
diff --git a/gcc/testsuite/gcc.dg/parse-decl-after-label.c b/gcc/testsuite/gcc.dg/parse-decl-after-label.c
new file mode 100644 (file)
index 0000000..f457c6a
--- /dev/null
@@ -0,0 +1,17 @@
+/* PR 29062 
+{ dg-do compile }
+{ dg-options "-fsyntax-only" }
+*/
+
+int f(x)
+{
+  if (x > 1) 
+    {
+      goto finish;
+    }
+  return x;
+  
+ finish:
+  int ret = 1; /* { dg-error "a label can only be part of a statement and a declaration is not a statement" } */
+  return ret;
+}