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]

C++ PATCH for c++/56395 (ICE with template typename)


When we're stripping typedefs from a TYPENAME_TYPE, we need to handle any template arguments it might have.

Tested x86_64-pc-linux-gnu, applying to trunk and 4.7.
commit db3871b6aed11204a7e3336c27bd565e61000bce
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Feb 22 10:20:00 2013 -0500

    	PR c++/56395
    	* tree.c (strip_typedefs): Strip typedefs from TYPENAME_TYPE template
    	args.

diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index 41c8759..75b4d51 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -1220,9 +1220,34 @@ strip_typedefs (tree t)
       }
       break;
     case TYPENAME_TYPE:
-      result = make_typename_type (strip_typedefs (TYPE_CONTEXT (t)),
-				   TYPENAME_TYPE_FULLNAME (t),
-				   typename_type, tf_none);
+      {
+	tree fullname = TYPENAME_TYPE_FULLNAME (t);
+	if (TREE_CODE (fullname) == TEMPLATE_ID_EXPR)
+	  {
+	    tree args = TREE_OPERAND (fullname, 1);
+	    tree new_args = copy_node (args);
+	    bool changed = false;
+	    for (int i = 0; i < TREE_VEC_LENGTH (args); ++i)
+	      {
+		tree arg = TREE_VEC_ELT (args, i);
+		tree strip_arg;
+		if (TYPE_P (arg))
+		  strip_arg = strip_typedefs (arg);
+		else
+		  strip_arg = strip_typedefs_expr (arg);
+		TREE_VEC_ELT (new_args, i) = strip_arg;
+		if (strip_arg != arg)
+		  changed = true;
+	      }
+	    if (changed)
+	      fullname = lookup_template_function (TREE_OPERAND (fullname, 0),
+						   new_args);
+	    else
+	      ggc_free (new_args);
+	  }
+	result = make_typename_type (strip_typedefs (TYPE_CONTEXT (t)),
+				     fullname, typename_type, tf_none);
+      }
       break;
     case DECLTYPE_TYPE:
       result = strip_typedefs_expr (DECLTYPE_TYPE_EXPR (t));
diff --git a/gcc/testsuite/g++.dg/template/typename19.C b/gcc/testsuite/g++.dg/template/typename19.C
new file mode 100644
index 0000000..735deb2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/typename19.C
@@ -0,0 +1,24 @@
+// PR c++/56395
+
+struct A
+{
+  template <class T> struct B { };
+};
+
+template <class T> struct D { };
+
+template <class T, class U> struct C
+{
+  typedef T _Type;
+  typedef typename T::template B<_Type> _BType;
+  D<_BType> d;
+};
+
+template <class T> struct C<T,T>
+{
+  typedef T _Type;
+  typedef typename T::template B<_Type> _BType;
+  D<_BType> d;
+};
+
+C<A,A> c;

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