Hi,

this bug is purely about error recovery. A while ago I fixed the first half, but for, eg:

int foo(x a) {
}

we still emit the pointless:

52987_2.C:1:14: error: expected ‘,’ or ‘;’ before ‘{’ token

In fact, we *already* have code helping error recovery in cp_parser_simple_declaration:

      /* If we have already issued an error message we don't need
         to issue another one.  */
      if (decl != error_mark_node
          || cp_parser_uncommitted_to_tentative_parse_p (parser))
        cp_parser_error (parser, "expected %<,%> or %<;%>");

but it doesn't trigger in such cases, because the decl is in fact != error_mark_node, trace of the error can be found only in its DECL_INITIAL (I noticed that only today ;) Thus the below, which so far appears to work well for me, passes testing on x86_64-linux (g++.old-deja/g++.law/init7.C included, which blocks even simpler solutions).

Thanks,
Paolo.

////////////////////////

/cp
2015-07-23  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/52987
        * parser.c (cp_parser_simple_declaration): Robustify check avoiding
        duplicated error messages.

/testsuite
2015-07-23  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/52987
        * g++.dg/parse/error57.C: New.
        * g++.dg/expr/string-2.C: Update.
Index: cp/parser.c
===================================================================
--- cp/parser.c (revision 226075)
+++ cp/parser.c (working copy)
@@ -11660,7 +11660,8 @@ cp_parser_simple_declaration (cp_parser* parser,
        {
          /* If we have already issued an error message we don't need
             to issue another one.  */
-         if (decl != error_mark_node
+         if ((decl != error_mark_node
+              && DECL_INITIAL (decl) != error_mark_node)
              || cp_parser_uncommitted_to_tentative_parse_p (parser))
            cp_parser_error (parser, "expected %<,%> or %<;%>");
          /* Skip tokens until we reach the end of the statement.  */
Index: testsuite/g++.dg/expr/string-2.C
===================================================================
--- testsuite/g++.dg/expr/string-2.C    (revision 226075)
+++ testsuite/g++.dg/expr/string-2.C    (working copy)
@@ -4,7 +4,7 @@
 char a[1];
 
 int foo(a = "") // { dg-error "invalid array assignment" }
-{ // { dg-error "" }
+{
   return 0;
 }
 
Index: testsuite/g++.dg/parse/error57.C
===================================================================
--- testsuite/g++.dg/parse/error57.C    (revision 0)
+++ testsuite/g++.dg/parse/error57.C    (working copy)
@@ -0,0 +1,4 @@
+// PR c++/52987
+
+int foo(x a) {  // { dg-error "9:'x' was not declared in this scope" }
+}

Reply via email to