public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ PATCH] Don't commit to tentative parse in  cp_parser_simple_declaration if there were parse errors (PR  c++/34269)
@ 2008-11-12 15:19 Jakub Jelinek
  2008-11-12 17:18 ` Mark Mitchell
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2008-11-12 15:19 UTC (permalink / raw)
  To: Mark Mitchell, Jason Merrill; +Cc: gcc-patches

Hi!

If there were parse errors, not committing to tentative parse
means it will be parsed again as expression and diagnostics emitted.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2008-11-12  Jakub Jelinek  <jakub@redhat.com>

	PR c++/34269
	* parser.c (cp_parser_simple_declaration): Don't commit
	to tentative parse if parse errors were seen.

	* g++.dg/cpp0x/decltype13.C: New test.
	* g++.dg/cpp0x/decltype-33837.C: Adjust dg-error pattern.
	* g++.dg/cpp0x/pr33839.C: Likewise.

--- gcc/cp/parser.c.jj	2008-11-10 11:34:14.000000000 +0100
+++ gcc/cp/parser.c	2008-11-12 13:08:26.000000000 +0100
@@ -8174,7 +8174,8 @@ cp_parser_simple_declaration (cp_parser*
      (After "int (" we might be looking at a functional cast.)  */
   if (decl_specifiers.any_specifiers_p
       && cp_lexer_next_token_is_not (parser->lexer, CPP_OPEN_PAREN)
-      && cp_lexer_next_token_is_not (parser->lexer, CPP_OPEN_BRACE))
+      && cp_lexer_next_token_is_not (parser->lexer, CPP_OPEN_BRACE)
+      && !cp_parser_error_occurred (parser))
     cp_parser_commit_to_tentative_parse (parser);
 
   /* Keep going until we hit the `;' at the end of the simple
--- gcc/testsuite/g++.dg/cpp0x/decltype13.C.jj	2008-11-12 13:14:14.000000000 +0100
+++ gcc/testsuite/g++.dg/cpp0x/decltype13.C	2008-11-12 13:12:44.000000000 +0100
@@ -0,0 +1,38 @@
+// PR c++/34269
+// { dg-do compile }
+
+void
+f1 ()
+{
+  __decltype;		// { dg-error "expected" }
+}
+
+void
+f2 ()
+{
+  __decltype (;		// { dg-error "expected" }
+}
+
+void
+f3 ()
+{
+  __decltype ();	// { dg-error "expected" }
+}
+
+void
+f4 ()
+{
+  __typeof__;		// { dg-error "expected" }
+}
+
+void
+f5 ()
+{
+  __typeof__ (;		// { dg-error "expected" }
+}
+
+void
+f6 ()
+{
+  __typeof__ ();	// { dg-error "expected" }
+}
--- gcc/testsuite/g++.dg/cpp0x/decltype-33837.C.jj	2008-11-12 13:19:16.000000000 +0100
+++ gcc/testsuite/g++.dg/cpp0x/decltype-33837.C	2008-11-12 13:19:16.000000000 +0100
@@ -2,6 +2,6 @@
 // PR c++/33837
 void foo()
 {
-  __decltype (A::foo()); // { dg-error "was not declared|expected initializer" }
+  __decltype (A::foo()); // { dg-error "was not declared|expected" }
   __decltype (B); // { dg-error "was not declared" }
 }
--- gcc/testsuite/g++.dg/cpp0x/pr33839.C.jj	2008-09-05 12:55:05.000000000 +0200
+++ gcc/testsuite/g++.dg/cpp0x/pr33839.C	2008-11-12 13:18:14.000000000 +0100
@@ -3,6 +3,6 @@ template<int> struct A;
 
 void foo()
 {
-  __decltype A<0>; // { dg-error "invalid declarator" }
+  __decltype A<0>; // { dg-error "invalid declarator|expected" }
   __decltype (A<0>); // { dg-error "must be an expression" }
 }

	Jakub

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

* Re: [C++ PATCH] Don't commit to tentative parse in cp_parser_simple_declaration  if there were parse errors (PR c++/34269)
  2008-11-12 15:19 [C++ PATCH] Don't commit to tentative parse in cp_parser_simple_declaration if there were parse errors (PR c++/34269) Jakub Jelinek
@ 2008-11-12 17:18 ` Mark Mitchell
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Mitchell @ 2008-11-12 17:18 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Jason Merrill, gcc-patches

Jakub Jelinek wrote:

> 2008-11-12  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR c++/34269
> 	* parser.c (cp_parser_simple_declaration): Don't commit
> 	to tentative parse if parse errors were seen.
> 
> 	* g++.dg/cpp0x/decltype13.C: New test.
> 	* g++.dg/cpp0x/decltype-33837.C: Adjust dg-error pattern.
> 	* g++.dg/cpp0x/pr33839.C: Likewise.

OK.

-- 
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713

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

end of thread, other threads:[~2008-11-12 17:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-12 15:19 [C++ PATCH] Don't commit to tentative parse in cp_parser_simple_declaration if there were parse errors (PR c++/34269) Jakub Jelinek
2008-11-12 17:18 ` Mark Mitchell

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).