public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ Patch] PR 52987
@ 2015-07-22 22:19 Paolo Carlini
  2015-07-23  7:46 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Paolo Carlini @ 2015-07-22 22:19 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jason Merrill

[-- Attachment #1: Type: text/plain, Size: 982 bytes --]

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.

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


[-- Attachment #2: CL_52987 --]
[-- Type: text/plain, Size: 318 bytes --]

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

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

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

	PR c++/52987
	* g++.dg/parse/error57.C: New.
	* g++.dg/expr/string-2.C: Update.

[-- Attachment #3: patch_52987 --]
[-- Type: text/plain, Size: 1298 bytes --]

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" }
+}

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [C++ Patch] PR 52987
  2015-07-22 22:19 [C++ Patch] PR 52987 Paolo Carlini
@ 2015-07-23  7:46 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2015-07-23  7:46 UTC (permalink / raw)
  To: Paolo Carlini, gcc-patches

OK.

Jason

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-07-23  3:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-22 22:19 [C++ Patch] PR 52987 Paolo Carlini
2015-07-23  7:46 ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).