aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorManuel López-Ibáñez <manu@gcc.gnu.org>2007-11-03 19:41:20 +0000
committerManuel López-Ibáñez <manu@gcc.gnu.org>2007-11-03 19:41:20 +0000
commit847c8ce4d147f2de0d99b517f7557f804e592867 (patch)
tree7bc7dbed0e4fd908371d348e8825c159f47093f4 /gcc
parent47c95bff6b78a2f8e632714172f1ba004d449cca (diff)
downloadgcc-847c8ce4d147f2de0d99b517f7557f804e592867.zip
gcc-847c8ce4d147f2de0d99b517f7557f804e592867.tar.gz
gcc-847c8ce4d147f2de0d99b517f7557f804e592867.tar.bz2
re PR c/29062 (unclear diagnostic for declaration after label)
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. testsuite/ * gcc.dg/20031223-1.c: Adjust error output. * gcc.dg/parse-decl-after-label.c: New. From-SVN: r129873
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/c-parser.c8
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/gcc.dg/20031223-1.c3
-rw-r--r--gcc/testsuite/gcc.dg/parse-decl-after-label.c17
5 files changed, 39 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index c78cf43..0ec6736 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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
diff --git a/gcc/c-parser.c b/gcc/c-parser.c
index 2914826..322f600 100644
--- a/gcc/c-parser.c
+++ b/gcc/c-parser.c
@@ -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 %<;%>");
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 0fec43d..4634c63 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
diff --git a/gcc/testsuite/gcc.dg/20031223-1.c b/gcc/testsuite/gcc.dg/20031223-1.c
index a022bf2..d44a9cd 100644
--- a/gcc/testsuite/gcc.dg/20031223-1.c
+++ b/gcc/testsuite/gcc.dg/20031223-1.c
@@ -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
index 0000000..f457c6a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/parse-decl-after-label.c
@@ -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;
+}