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++/28110: ICE with invalid template constant parameter


The following testcase triggers an ICE since GCC 4.1.0:

  template<int> struct A {};

  template<typename T> struct B
  {
    template<T I> B(A<I>);
  };

  B<double> a=A<0>();

bug.cc: In instantiation of 'B<double>':
bug.cc:8:   instantiated from here
bug.cc:5: error: 'double' is not a valid type for a template constant parameter
bug.cc:8: internal compiler error: in template_decl_level, at cp/pt.c:9993
Please submit a full bug report, [etc.]

We ICE because we pass an error_mark_node to template_decl_level which
triggers an assert. The following patch fixes this by checking for
error_mark_node in unify before calling template_decl_level.

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

Regards,
Volker

:ADDPATCH C++:


2006-06-21  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c++/28110
	* pt.c (unify) <case TEMPLATE_PARM_INDEX>: Check for invalid
	parameters.

===================================================================
--- gcc/gcc/cp/pt.c	(revision 114800)
+++ gcc/gcc/cp/pt.c	(working copy)
@@ -10281,6 +10281,8 @@ unify (tree tparms, tree targs, tree parm,
 
     case TEMPLATE_PARM_INDEX:
       tparm = TREE_VALUE (TREE_VEC_ELT (tparms, 0));
+      if (tparm == error_mark_node)
+	return 1;
 
       if (TEMPLATE_PARM_LEVEL (parm)
 	  != template_decl_level (tparm))
===================================================================

2006-06-21  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c++/28110
	* g++.dg/template/crash53.C: New test.

===================================================================
--- gcc/gcc/testsuite/g++.dg/template/crash53.C	2005-08-29 00:25:44 +0200
+++ gcc/gcc/testsuite/g++.dg/template/crash53.C	2006-06-20 16:44:06 +0200
@@ -0,0 +1,11 @@
+// PR c++/28110
+// { dg-do compile }
+
+template<int> struct A {};
+
+template<typename T> struct B
+{
+  template<T I> B(A<I>);  // { dg-error "template constant parameter" }
+};
+
+B<double> a=A<0>();  // { dg-error "non-scalar type" }
===================================================================



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