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] Fix PR c++/19498: ICE on invalid reference in templateparameter


Consider the following testcase:

  template<typename T> struct A
  {
      template<T&> struct B;
  };

  A<void> a;

When instantiating A<void> the compiler has to substitute T with
void in the declaration of struct B. This is done in tsubst_decl by
calling tsubst_template_args. Since void& is an invalid type, the
substitution fails and tsubst_template_args correctly returns
error_mark_node.

However, the compiler fails to check for the error_mark_node and instead
calls retrieve_specialization with an error_mark_node as second argument.
This results in an ICE.

The attached patch fixes the ICE by adding a check for error_mark_node
and adds the above testcase.

Bootstrapped and regtested on i686-pc-linux-gnu.
Ok for mainline?

Regards,
Volker


2005-08-03  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c++/19498
	* pt.c (tsubst_decl) <case TEMPLATE_DECL>: Return ERROR_MARK_NODE
	if substitution of template args did not succeed.

===================================================================
--- gcc/gcc/cp/pt.c	1 Aug 2005 04:02:26 -0000	1.1019
+++ gcc/gcc/cp/pt.c	3 Aug 2005 15:53:36 -0000
@@ -6224,6 +6224,8 @@ tsubst_decl (tree t, tree args, tsubst_f
 	  : DECL_TI_ARGS (DECL_TEMPLATE_RESULT (t));
 	full_args = tsubst_template_args (tmpl_args, args,
 					  complain, in_decl);
+	if (full_args == error_mark_node)
+	  return error_mark_node;
 
 	/* tsubst_template_args doesn't copy the vector if
 	   nothing changed.  But, *something* should have
===================================================================


2005-08-03  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c++/19498
	* g++.dg/template/instantiate7.C: New test.

===================================================================
--- gcc/gcc/testsuite/g++.dg/template/instantiate7.C	2005-06-27 13:32:40.055820328 +0200
+++ gcc/gcc/testsuite/g++.dg/template/instantiate7.C	2005-08-03 18:03:47.000000000 +0200
@@ -0,0 +1,10 @@
+// PR c++/19498
+// Origin: Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
+// { dg-do compile }
+
+template<typename T> struct A
+{
+    template<T&> struct B;  // { dg-error "reference to void" }
+};
+
+A<void> a;                  // { dg-error "instantiated" }
===================================================================



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