C++ PATCH for c++/45698 (crash with variadics)

2011-05-25 Thread Jason Merrill
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 000..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 { };
+
+templateclass... Ts
+struct A {
+  templatetypename T struct N { };
+  tupleNTs... tup;
+};
+
+int main()
+{
+  Aint, 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))


Re: C++ PATCH for c++/45698 (crash with variadics)

2011-05-25 Thread Nathan Froyd
On 05/25/2011 03:45 PM, Jason Merrill wrote:
 While looking at this, I also noticed that print_node expects everything to
 have TREE_TYPE, which is no longer correct.

Technically, I think this is not true; everything inherits from tree_common;
or at least tree_typed.  (I had the bit of print_node fixing in one of my
patches; thanks for getting it in ahead of me!)  Once the STATEMENT_LIST and
BLOCK slimming patches are in, there will indeed be things that don't have
TREE_TYPE.  If something doesn't have TREE_TYPE, then the Right Thing to do
would be to fix the tree structure so that it only inherits from tree_base.

Like the following (totally untested) patch.  WDYT?  (It's certainly possible
that other C++-specific trees could be modified in the same way;
tree_static_assert jumps out, for instance.)

-Nathan

gcc/cp/
* cp-tree.h (struct tree_argument_pack_select): Inherit from
tree_base.

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index ada01fb..a315986 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -534,7 +534,7 @@ struct GTY (()) tree_static_assert {
 };

 struct GTY (()) tree_argument_pack_select {
-  struct tree_common common;
+  struct tree_base base;
   tree argument_pack;
   int index;
 };


Re: C++ PATCH for c++/45698 (crash with variadics)

2011-05-25 Thread Jason Merrill

On 05/25/2011 03:56 PM, Nathan Froyd wrote:

* cp-tree.h (struct tree_argument_pack_select): Inherit from
tree_base.


OK if it passes testing.

Jason