2007-12-04 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
authormanu <manu@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 4 Dec 2007 21:10:09 +0000 (21:10 +0000)
committermanu <manu@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 4 Dec 2007 21:10:09 +0000 (21:10 +0000)
* c-parser (c_parser_statement_after_labels): Move error from here...
(c_parser_label): ... to here. Check that the declaration is not
actually just another label.
testsuite/
* gcc.dg/parse-decl-after-if.c: New.
* gcc.dg/20031223-1.c: Adjust.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@130606 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-if.c [new file with mode: 0644]

index 9c32e26..a7eb6a2 100644 (file)
@@ -1,3 +1,9 @@
+2007-12-04  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
+
+       * c-parser (c_parser_statement_after_labels): Move error from here...
+       (c_parser_label): ... to here. Check that the declaration is not
+       actually just another label.
+
 2007-12-04  Richard Guenther  <rguenther@suse.de>
 
        PR middle-end/34334
index 1e32b5b..c2e5435 100644 (file)
@@ -3638,7 +3638,20 @@ c_parser_label (c_parser *parser)
        }
     }
   if (label)
-    SET_EXPR_LOCATION (label, loc1);
+    {
+      SET_EXPR_LOCATION (label, loc1);
+      if (c_parser_next_token_starts_declspecs (parser)
+         && !(c_parser_next_token_is (parser, CPP_NAME)
+              && c_parser_peek_2nd_token (parser)->type == CPP_COLON))
+       {
+         error ("%Ha label can only be part of a statement and "
+                "a declaration is not a statement",
+                &c_parser_peek_token (parser)->location);
+         c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false, 
+                                        /*nested*/ true, /*empty_ok*/ false,
+                                        /*start_attr_ok*/ true);
+       }
+    }
 }
 
 /* Parse a statement (C90 6.6, C99 6.8).
@@ -3864,16 +3877,6 @@ c_parser_statement_after_labels (c_parser *parser)
       break;
     default:
     expr_stmt:
-      if (c_parser_next_token_starts_declspecs (parser)) 
-       {
-         error ("%Ha label can only be part of a statement and "
-                "a declaration is not a statement",
-                &c_parser_peek_token (parser)->location);
-         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 13e2cba..a4fc563 100644 (file)
@@ -1,3 +1,8 @@
+2007-12-04  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
+       
+       * gcc.dg/parse-decl-after-if.c: New.
+       * gcc.dg/20031223-1.c: Adjust.
+       
 2007-12-04  Douglas Gregor  <doug.gregor@gmail.com>
 
        PR c++/33509
index d44a9cd..c2f35fc 100644 (file)
@@ -9,4 +9,5 @@ void f ()
 {
  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 } */
+ /* { dg-error "label at end of compound statement" "" { target *-*-* } 10 } */
 }
diff --git a/gcc/testsuite/gcc.dg/parse-decl-after-if.c b/gcc/testsuite/gcc.dg/parse-decl-after-if.c
new file mode 100644 (file)
index 0000000..f48e6df
--- /dev/null
@@ -0,0 +1,11 @@
+/* Parse error recovery
+{ dg-do compile }
+{ dg-options "-fsyntax-only" }
+*/
+
+void f(x)
+{
+  if (x > 1)
+    int ret = 1; /* { dg-error "expected expression before 'int'" } */
+
+}