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


This is a pretty straightforward bug: tsubst doesn't work if we've thrown away the outer levels of template arguments. So keep them around.

Tested x86_64-pc-linux-gnu, applied to trunk.
2009-06-29  Jason Merrill  <jason@redhat.com>

	PR c++/40274
	* error.c (dump_template_parms): Pass all args to
	count_non_default_template_args.
	(count_non_default_template_args): Pull out the inner ones.

diff --git a/gcc/cp/error.c b/gcc/cp/error.c
index 98dacb1..fa97a3b 100644
--- a/gcc/cp/error.c
+++ b/gcc/cp/error.c
@@ -165,7 +165,8 @@ dump_template_argument (tree arg, int flags)
 static int
 count_non_default_template_args (tree args, tree params)
 {
-  int n = TREE_VEC_LENGTH (args);
+  tree inner_args = INNERMOST_TEMPLATE_ARGS (args);
+  int n = TREE_VEC_LENGTH (inner_args);
   int last;
 
   if (params == NULL_TREE || !flag_pretty_templates)
@@ -184,7 +185,7 @@ count_non_default_template_args (tree args, tree params)
 	  def = tsubst_copy_and_build (def, args, tf_none, NULL_TREE, false, true);
 	  --processing_template_decl;
 	}
-      if (!cp_tree_equal (TREE_VEC_ELT (args, last), def))
+      if (!cp_tree_equal (TREE_VEC_ELT (inner_args, last), def))
         break;
     }
 
@@ -1434,7 +1435,7 @@ dump_template_parms (tree info, int primary, int flags)
   pp_cxx_begin_template_argument_list (cxx_pp);
 
   /* Be careful only to print things when we have them, so as not
-	 to crash producing error messages.  */
+     to crash producing error messages.  */
   if (args && !primary)
     {
       int len, ix;
@@ -1443,11 +1444,9 @@ dump_template_parms (tree info, int primary, int flags)
 		     ? DECL_INNERMOST_TEMPLATE_PARMS (TI_TEMPLATE (info))
 		     : NULL_TREE);
 
-      if (TMPL_ARGS_HAVE_MULTIPLE_LEVELS (args))
-	args = TREE_VEC_ELT (args, TREE_VEC_LENGTH (args) - 1);
-
       len = count_non_default_template_args (args, params);
 
+      args = INNERMOST_TEMPLATE_ARGS (args);
       for (ix = 0; ix != len; ix++)
 	{
 	  tree arg = TREE_VEC_ELT (args, ix);
diff --git a/gcc/testsuite/g++.dg/template/debug1.C b/gcc/testsuite/g++.dg/template/debug1.C
new file mode 100644
index 0000000..a2c1577
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/debug1.C
@@ -0,0 +1,18 @@
+// PR c++/40274
+// { dg-options "-g" }
+
+template <class T> struct valuelist_types
+{
+ struct null { };
+ template <T V, class next=null> struct list { };
+};
+
+template <unsigned D> void foo()
+{
+ typename valuelist_types<unsigned>::template list<D> v;
+}
+
+void bar()
+{
+ valuelist_types<unsigned>::list<2> v;
+}

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