This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH] Handle template <typename... T> void fn (const T...) (PR c++/31434)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Jason Merrill <jason at redhat dot com>, Doug Gregor <doug dot gregor at gmail dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Thu, 27 Sep 2007 14:36:22 -0400
- Subject: [C++ PATCH] Handle template <typename... T> void fn (const T...) (PR c++/31434)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
I can't find anything in N2152 that would make this invalid, eventhough the
PR is marked as accepts-invalid, ice-on-invalid. Type of function parameter
pack clearly is accepted for various types involving somehow a template
parameter pack, e.g. if T is a template parameter pack, function parameter
packs const T &..., const T * const ..., T &... etc. are all accepted.
But const T... or volatile T... is not. Assuming that they are valid,
the problem is that for these two the type is created through
cp_build_qualified_type_real, which will make a qualified variant of the
TYPE_PACK_EXPANSION type. But the generic build_variant_type_copy
function of course doesn't populate PACK_EXPANSION_PARAMETER_PACKS
aka TREE_CHAIN of the new TYPE_PACK_EXPANSION.
The following patch fixes this by handling it similarly to
TYPE_PTRMEMFUNC_P types.
2007-09-27 Jakub Jelinek <jakub@redhat.com>
PR c++/31434
* tree.c (cp_build_qualified_type_real): Handle TYPE_PACK_EXPANSION
qualification by creating qualified PACK_EXPANSION_PATTERN and
then calling make_pack_expansion on it.
* g++.dg/cpp0x/variadic80.C: New test.
--- gcc/cp/tree.c.jj 2007-09-24 22:59:21.000000000 +0200
+++ gcc/cp/tree.c 2007-09-27 20:06:04.000000000 +0200
@@ -773,6 +773,13 @@ cp_build_qualified_type_real (tree type,
t = cp_build_qualified_type_real (t, type_quals, complain);
return build_ptrmemfunc_type (t);
}
+ else if (TREE_CODE (type) == TYPE_PACK_EXPANSION)
+ {
+ tree t = PACK_EXPANSION_PATTERN (type);
+
+ t = cp_build_qualified_type_real (t, type_quals, complain);
+ return make_pack_expansion (t);
+ }
/* A reference or method type shall not be cv qualified.
[dcl.ref], [dct.fct] */
--- gcc/testsuite/g++.dg/cpp0x/variadic80.C.jj 2007-09-27 20:20:22.000000000 +0200
+++ gcc/testsuite/g++.dg/cpp0x/variadic80.C 2007-09-27 20:23:08.000000000 +0200
@@ -0,0 +1,28 @@
+// PR c++/31434
+// { dg-do run }
+// { dg-options "-std=c++0x" }
+
+extern "C" void abort ();
+
+template<typename... T> inline int foo (const T...) { return 1; }
+template<typename... T> inline int foo (const T *...) { return 2; }
+
+void
+bar (int *a)
+{
+ a[0] = foo (0);
+ a[1] = foo (*a);
+ a[2] = foo<int> (a);
+ a[3] = foo<int> (2, 3, 4, 5);
+ a[4] = foo<int> (a, a + 1, a + 2);
+}
+
+int
+main ()
+{
+ int a[5];
+ bar (a);
+ if (a[0] != 1 || a[1] != 1 || a[2] != 2 || a[3] != 1 || a[4] != 2)
+ abort ();
+ return 0;
+}
Jakub