45698 was actually fixed in 4.5.0, but before I closed it I checked to see how the testcase was doing with the current compiler, and found that it was crashing again. This turned out to be because of Nathan's recent tree-slimming work; ARGUMENT_PACK_SELECT doesn't have TREE_TYPE, so we crash when we try to look at it in value_dependent_expression_p. But we shouldn't be treating it as an expression in the first place, since it could be either a type or value argument.

Fixed by looking through ARGUMENT_PACK_SELECT before we decide what sort of template argument we're dealing with.

While looking at this, I also noticed that print_node expects everything to have TREE_TYPE, which is no longer correct. And I made print_node more useful for ARGUMENT_PACK_SELECT.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit 0b5532a57ea85765d6baed5eff0abaaabac1aaaf
Author: Jason Merrill <ja...@redhat.com>
Date:   Wed May 25 13:24:47 2011 -0400

    	PR c++/45698
    	* pt.c (dependent_template_arg_p): See through ARGUMENT_PACK_SELECT.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index c3c759e..c9c25cd 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -18759,6 +18759,9 @@ dependent_template_arg_p (tree arg)
   if (arg == error_mark_node)
     return true;
 
+  if (TREE_CODE (arg) == ARGUMENT_PACK_SELECT)
+    arg = ARGUMENT_PACK_SELECT_ARG (arg);
+
   if (TREE_CODE (arg) == TEMPLATE_DECL
       || TREE_CODE (arg) == TEMPLATE_TEMPLATE_PARM)
     return dependent_template_p (arg);
diff --git a/gcc/testsuite/g++.dg/cpp0x/variadic110.C b/gcc/testsuite/g++.dg/cpp0x/variadic110.C
new file mode 100644
index 0000000..86f1bb1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/variadic110.C
@@ -0,0 +1,15 @@
+// PR c++/45698
+// { dg-options -std=c++0x }
+
+template <class... Ts> struct tuple { };
+
+template<class... Ts>
+struct A {
+  template<typename T> struct N { };
+  tuple<N<Ts>...> tup;
+};
+
+int main()
+{
+  A<int, double> a;
+}
commit 46cccd60afea40407a278f6d937373e0121c24ee
Author: Jason Merrill <ja...@redhat.com>
Date:   Wed May 25 13:32:05 2011 -0400

    	* print-tree.c (print_node): Only look at TREE_TYPE if TS_TYPED.
    	* cp/ptree.c (cxx_print_xnode): Handle ARGUMENT_PACK_SELECT.

diff --git a/gcc/cp/ptree.c b/gcc/cp/ptree.c
index a4c3ed5..5c9626e 100644
--- a/gcc/cp/ptree.c
+++ b/gcc/cp/ptree.c
@@ -221,6 +221,12 @@ cxx_print_xnode (FILE *file, tree node, int indent)
 	  fprintf (file, "pending_template");
 	}
       break;
+    case ARGUMENT_PACK_SELECT:
+      print_node (file, "pack", ARGUMENT_PACK_SELECT_FROM_PACK (node),
+		  indent+4);
+      indent_to (file, indent + 3);
+      fprintf (file, "index %d", ARGUMENT_PACK_SELECT_INDEX (node));
+      break;
     default:
       break;
     }
diff --git a/gcc/print-tree.c b/gcc/print-tree.c
index 3b5edeb..58c9613 100644
--- a/gcc/print-tree.c
+++ b/gcc/print-tree.c
@@ -321,7 +321,7 @@ print_node (FILE *file, const char *prefix, tree node, int indent)
       if (indent <= 4)
 	print_node_brief (file, "type", TREE_TYPE (node), indent + 4);
     }
-  else
+  else if (CODE_CONTAINS_STRUCT (code, TS_TYPED))
     {
       print_node (file, "type", TREE_TYPE (node), indent + 4);
       if (TREE_TYPE (node))

Reply via email to