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]

PATCH: PR c++/28301: [4.3/4.4/4.5 regression] ICE with broken specialization


When we see an error, we shouldn't skip to the the end of block or
statement if we are already at the end of block or statement. OK
for trunk, 4.4 and 4.3 if there are no regressions.

Thanks.

H.J.
---
gcc/cp/

2009-03-31  H.J. Lu  <hongjiu.lu@intel.com>

	PR c++/28301
	* parser.c (cp_parser_single_declaration): Don't skip to
	the end of block or statement on error when the next token
	is '}'.

gcc/testsuite/

2009-03-31  H.J. Lu  <hongjiu.lu@intel.com>

	PR c++/28301
	* g++.dg/template/pr28301.C: New.

--- gcc/cp/parser.c.pr28301	2009-03-31 09:14:28.000000000 -0700
+++ gcc/cp/parser.c	2009-03-31 10:28:07.000000000 -0700
@@ -17918,10 +17918,19 @@ cp_parser_single_declaration (cp_parser*
   parser->qualifying_scope = NULL_TREE;
   parser->object_scope = NULL_TREE;
   /* Look for a trailing `;' after the declaration.  */
-  if (!function_definition_p
-      && (decl == error_mark_node
-	  || !cp_parser_require (parser, CPP_SEMICOLON, "%<;%>")))
-    cp_parser_skip_to_end_of_block_or_statement (parser);
+  if (!function_definition_p)
+    {
+      if (decl == error_mark_node)
+	{
+	  /* Don't skip to the end of block or statement when the next
+	     token is '}'.  */
+	  cp_token *token = cp_lexer_peek_token (parser->lexer);
+	  if (token->type != CPP_CLOSE_BRACE)
+	    cp_parser_skip_to_end_of_block_or_statement (parser);
+	}
+      else if (!cp_parser_require (parser, CPP_SEMICOLON, "%<;%>"))
+	cp_parser_skip_to_end_of_block_or_statement (parser);
+    }
 
   return decl;
 }
--- gcc/testsuite/g++.dg/template/pr28301.C.pr28301	2009-03-31 10:30:10.000000000 -0700
+++ gcc/testsuite/g++.dg/template/pr28301.C	2009-03-31 10:29:45.000000000 -0700
@@ -0,0 +1,18 @@
+// PR c++/28301
+// { dg-do compile }
+
+template<typename> struct A
+{
+    template<int> void foo()
+};	// { dg-error "initializer" }
+
+template<> struct A<void>
+{
+    template<int> void foo();
+};
+
+void bar()
+{
+    A<void> a;
+    a.foo<0>();
+}


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