Patchwork [C++] Handle *_TYPE in tsubst_copy (PR c++/47022)

login
register
mail settings
Submitter Jakub Jelinek
Date Jan. 1, 2011, 6:27 p.m.
Message ID <20110101182742.GX16156@tyan-ft48-01.lab.bos.redhat.com>
Download mbox | patch
Permalink /patch/77148/
State New
Headers show

Comments

Jakub Jelinek - Jan. 1, 2011, 6:27 p.m.
Hi!

On the following testcase tsubst_copy called by VA_ARG_EXPR
handling in tsubst_copy_and_build ICEs because tsubst_copy doesn't
handle REAL_TYPE since recent changes.
One fix is attached, another possibility (untested) would be to pass through
all TYPE_Ps to tsubst in default: for tsubst_copy, another is
use tsubst instead of tsubst_copy on VA_ARG_EXPR's second argument in
tsubst_copy_and_build (or any combination of those).

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2011-01-01  Jakub Jelinek  <jakub@redhat.com>

	PR c++/47022
	* pt.c (tsubst): Handle FIXED_POINT_TYPE.
	(tsubst_copy): Handle VOID_TYPE, BOOLEAN_TYPE, REAL_TYPE,
	NULLPTR_TYPE, FIXED_POINT_TYPE, COMPLEX_TYPE and VECTOR_TYPE.

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


	Jakub
Jason Merrill - Jan. 5, 2011, 1:42 p.m.
On 01/01/2011 01:27 PM, Jakub Jelinek wrote:
> One fix is attached, another possibility (untested) would be to pass through
> all TYPE_Ps to tsubst in default: for tsubst_copy, another is
> use tsubst instead of tsubst_copy on VA_ARG_EXPR's second argument in
> tsubst_copy_and_build (or any combination of those).

The last of those, please.

Jason

Patch

--- gcc/cp/pt.c.jj	2010-12-28 12:32:59.000000000 +0100
+++ gcc/cp/pt.c	2010-12-31 11:44:50.000000000 +0100
@@ -10441,6 +10441,7 @@  tsubst (tree t, tree args, tsubst_flags_
     case COMPLEX_TYPE:
     case VECTOR_TYPE:
     case BOOLEAN_TYPE:
+    case FIXED_POINT_TYPE:
     case NULLPTR_TYPE:
     case LANG_TYPE:
       return t;
@@ -11612,6 +11613,13 @@  tsubst_copy (tree t, tree args, tsubst_f
     case FUNCTION_TYPE:
     case METHOD_TYPE:
     case ARRAY_TYPE:
+    case VOID_TYPE:
+    case BOOLEAN_TYPE:
+    case REAL_TYPE:
+    case NULLPTR_TYPE:
+    case FIXED_POINT_TYPE:
+    case COMPLEX_TYPE:
+    case VECTOR_TYPE:
     case TYPENAME_TYPE:
     case UNBOUND_CLASS_TEMPLATE:
     case TYPEOF_TYPE:
--- gcc/testsuite/g++.dg/template/stdarg1.C.jj	2010-12-31 11:56:29.000000000 +0100
+++ gcc/testsuite/g++.dg/template/stdarg1.C	2010-12-31 11:55:56.000000000 +0100
@@ -0,0 +1,53 @@ 
+// PR c++/47022
+// { dg-do compile }
+
+#include <cstdarg>
+
+template <typename T>
+void
+f1 (T *p, va_list ap)
+{
+  *p = va_arg (ap, long double);
+  *p += va_arg (ap, double);
+}
+
+template <typename T>
+void
+f2 (T *p, va_list ap)
+{
+  *p = __real__ va_arg (ap, _Complex int);
+  *p += __imag__ va_arg (ap, _Complex double);
+  *p += __imag__ va_arg (ap, _Complex long double);
+}
+
+template <typename T>
+void
+f3 (T *p, va_list ap)
+{
+  *p = va_arg (ap, T);
+}
+
+void
+foo (int x, va_list ap)
+{
+  if (x == 0)
+    {
+      long double ld;
+      f1 (&ld, ap);
+    }
+  else if (x == 1)
+    {
+      int i;
+      f2 (&i, ap);
+    }
+  else if (x == 2)
+    {
+      long double ld;
+      f3 (&ld, ap);
+    }
+  else if (x == 3)
+    {
+      _Complex double cd;
+      f3 (&cd, ap);
+    }
+}