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] Fallout from Fix PR c++/28250: ICE with invalid catch


On 16 Jul, Mark Mitchell wrote:
> Volker Reichelt wrote:
> 
>> 2006-07-14  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
>> 
>> 	PR c++/28250
>> 	* name-lookup.c (pushdecl_maybe_friend): Return early on
>> 	error_mark_node.
>> 	* except.c (expand_start_catch_block): Use error_mark_node instead
>> 	of NULL_TREE for invalid decls.
>> 	* parser.c (cp_parser_exception_declaration): Return error_mark_node
>> 	on invalid catch parameter. Simplify.
> 
> OK, thanks.

Alas there's some fallout from the patch for PR 28250, because not
all parts of the compiler can handle the error_mark_nodes. :-(
The compiler now ICE's on the following code snippet:

  template<int> void foo()
  {
    try {}
    catch () {}
  }

  template void foo<0>();

bug.cc: In function 'void foo()':
bug.cc:4: error: expected type-specifier before ')' token
bug.cc: In function 'void foo() [with int <anonymous> = 0]':
bug.cc:7:   instantiated from here
bug.cc:4: internal compiler error: tree check: expected var_decl or function_decl, have error_mark in tsubst_expr, at cp/pt.c:8494
Please submit a full bug report, [etc.]

The following patch fixes that by not trying to set
DECL_TEMPLATE_INSTANTIATED (decl) = 1;
for decl == error_mark_node in tsubst_expr.
It also reorganizes the code a little to avoid a useless else branch
and duplicate evaluation of HANDLER_PARMS (t).

Bootstrapped and regtested on x86_64-unknown-linux-gnu.
Ok for mainline?

Regards,
Volker

:ADDPATCH C++:


2006-07-20  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c++/28250
	* pt.c (tsubst_expr): Only apply DECL_TEMPLATE_INSTANTIATED to
	valid decls.  Cleanup.

===================================================================
--- gcc/gcc/cp/pt.c	(revision 115576)
+++ gcc/gcc/cp/pt.c	(working copy)
@@ -8481,20 +8481,18 @@
 
     case HANDLER:
       {
-	tree decl;
+	tree decl = HANDLER_PARMS (t);
 
-	stmt = begin_handler ();
-	if (HANDLER_PARMS (t))
+	if (decl)
 	  {
-	    decl = HANDLER_PARMS (t);
 	    decl = tsubst (decl, args, complain, in_decl);
 	    /* Prevent instantiate_decl from trying to instantiate
 	       this variable.  We've already done all that needs to be
 	       done.  */
-	    DECL_TEMPLATE_INSTANTIATED (decl) = 1;
+	    if (decl != error_mark_node)
+	      DECL_TEMPLATE_INSTANTIATED (decl) = 1;
 	  }
-	else
-	  decl = NULL_TREE;
+	stmt = begin_handler ();
 	finish_handler_parms (decl, stmt);
 	tsubst_expr (HANDLER_BODY (t), args, complain, in_decl);
 	finish_handler (stmt);
===================================================================

2006-07-20  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c++/28250
	* g++.dg/eh/catch3.C: New test.

===================================================================
--- gcc/gcc/testsuite/g++.dg/eh/catch3.C	2005-08-29 00:25:44 +0200
+++ gcc/gcc/testsuite/g++.dg/eh/catch3.C	2006-07-20 17:38:45 +0200
@@ -0,0 +1,10 @@
+// PR c++/28250
+// { dg-do compile }
+
+template<int> void foo()
+{
+  try {}
+  catch () {}  // { dg-error "type-specifier" }
+}
+
+template void foo<0>();
===================================================================



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