public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ PATCH] Handle template <typename... T> void fn (const T...) (PR c++/31434)
@ 2007-09-27 19:29 Jakub Jelinek
  2007-09-27 19:50 ` Jason Merrill
  0 siblings, 1 reply; 3+ messages in thread
From: Jakub Jelinek @ 2007-09-27 19:29 UTC (permalink / raw)
  To: Jason Merrill, Doug Gregor; +Cc: gcc-patches

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [C++ PATCH] Handle template <typename... T> void fn (const T...)  (PR c++/31434)
  2007-09-27 19:29 [C++ PATCH] Handle template <typename... T> void fn (const T...) (PR c++/31434) Jakub Jelinek
@ 2007-09-27 19:50 ` Jason Merrill
  2007-09-28 16:39   ` Paolo Carlini
  0 siblings, 1 reply; 3+ messages in thread
From: Jason Merrill @ 2007-09-27 19:50 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Doug Gregor, gcc-patches

OK.

Jason

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [C++ PATCH] Handle template <typename... T> void fn (const T...)   (PR c++/31434)
  2007-09-27 19:50 ` Jason Merrill
@ 2007-09-28 16:39   ` Paolo Carlini
  0 siblings, 0 replies; 3+ messages in thread
From: Paolo Carlini @ 2007-09-28 16:39 UTC (permalink / raw)
  Cc: Jakub Jelinek, gcc-patches

Jakub, I think you added the ChangeLog entry for this fix to:
   
    trunk/gcc/ChangeLog

instead of
   
    trunk/gcc/cp/ChangeLog

Thanks,
Paolo.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-09-28 15:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-09-27 19:29 [C++ PATCH] Handle template <typename... T> void fn (const T...) (PR c++/31434) Jakub Jelinek
2007-09-27 19:50 ` Jason Merrill
2007-09-28 16:39   ` Paolo Carlini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).