This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C++ PATCH] Don't commit to tentative parse in cp_parser_simple_declaration if there were parse errors (PR c++/34269)


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]