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++/37142


Hello,

This patches fixes an ICE that happens on the attached test case while parsing the simple declaration A<long, 0, B> a;

During the parsing of the template-id A<long, 0, B> we try to lookup the template declaration A. This eventually triggers a call to coerce_template_parms that indirectly dies in dependent_type_p, called by coerce_template_template_parm. The ICE happens on the assert:
gcc_assert (TREE_CODE (type) != TEMPLATE_TYPE_PARM || is_auto (type)); because processing_template_decl is not set.


The patch uses uses_template_parms instead of dependent_type_p. That function is a superset of dependent_type_p that properly sets processing_template_decl and both should be functionally equivalent when called with a type class node.

Actually there are two physical patches, of for the 4.3 branch and the other for trunk. They are equivalent.

The patch passes regtests on trunk and gcc-4_3-branch for the x86_64 architecture. OK for both branches ?

Thanks,

Dodji.
gcc/cp/ChangeLog:
2008-11-19  Dodji Seketeli  <dodji@redhat.com>

	* pt.c (coerce_template_template_parm): Use the more robust
	uses_template_parms instead of dependent_type_p.

gcc/testsuite/ChangeLog:
2008-11-19  Dodji Seketeli  <dodji@redhat.com>

	* g++.dg/template/crash71.C: New test.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 721f02b..67654df 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -3962,7 +3962,7 @@ coerce_template_template_parms (tree parm_parms,
 	       D<int, C> d;
 
 	     i.e. the parameter list of TT depends on earlier parameters.  */
-	  if (!dependent_type_p (TREE_TYPE (arg))
+	  if (!uses_template_parms (TREE_TYPE (arg))
 	      && !same_type_p
 		    (tsubst (TREE_TYPE (parm), outer_args, complain, in_decl),
 			     TREE_TYPE (arg)))
diff --git a/gcc/testsuite/g++.dg/template/crash71.C b/gcc/testsuite/g++.dg/template/crash71.C
new file mode 100644
index 0000000..18ef338
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/crash71.C
@@ -0,0 +1,16 @@
+// Contributed by Dodji Seketeli <dodji@redhat.com>
+// Origin: PR c++/37142
+// { dg-do compile }
+
+template<typename T, const T a, template <typename U, U u> class W> struct A {};
+
+template<typename T, const T t> struct B {};
+
+int
+main ()
+{
+  A<long, 0, B> a;
+  return 0;
+}
+
+
gcc/cp/ChangeLog:
2008-11-19  Dodji Seketeli  <dodji@redhat.com>

	* pt.c (coerce_template_template_parm): Use the more robust
	uses_template_parms instead of dependent_type_p.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 13a2361..3342049 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -4688,7 +4688,7 @@ coerce_template_template_parm (tree parm,
 	   D<int, C> d;
 
 	 i.e. the parameter list of TT depends on earlier parameters.  */
-      if (!dependent_type_p (TREE_TYPE (arg))
+      if (!uses_template_parms (TREE_TYPE (arg))
 	  && !same_type_p
 	        (tsubst (TREE_TYPE (parm), outer_args, complain, in_decl),
 		 TREE_TYPE (arg)))
diff --git a/gcc/testsuite/g++.dg/template/crash85.C b/gcc/testsuite/g++.dg/template/crash85.C
new file mode 100644
index 0000000..e0b6ee1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/crash85.C
@@ -0,0 +1,15 @@
+// Contributed by Dodji Seketeli <dodji@redhat.com>
+// Origin: PR c++/37142
+// { dg-do compile }
+
+template<typename T, const T a, template <typename U, U u> class W> struct A {};
+
+template<typename T, const T t> struct B {};
+
+int
+main ()
+{
+  A<long, 0, B> a;
+  return 0;
+}
+

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