c++: Fix decltype of empty pack expansion of parm.
authorJason Merrill <jason@redhat.com>
Wed, 5 Feb 2020 22:59:28 +0000 (17:59 -0500)
committerJason Merrill <jason@redhat.com>
Wed, 5 Feb 2020 23:38:23 +0000 (18:38 -0500)
In unevaluated context, we only substitute a single PARM_DECL, not the
entire chain, but the handling of an empty pack expansion was missing that
check.

PR c++/93140
* pt.c (tsubst_decl) [PARM_DECL]: Check cp_unevaluated_operand in
handling of TREE_CHAIN for empty pack.

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/g++.dg/cpp0x/variadic-parm1.C [new file with mode: 0644]

index 12bbecfdda181de9b40fe88a57336f0077a6f9da..6a7ba564d1280a03e82539355bffab8cd4037a05 100644 (file)
@@ -1,3 +1,9 @@
+2020-02-05  Jason Merrill  <jason@redhat.com>
+
+       PR c++/93140
+       * pt.c (tsubst_decl) [PARM_DECL]: Check cp_unevaluated_operand in
+       handling of TREE_CHAIN for empty pack.
+
 2020-02-05  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/93557
index 40ff3c3a089ca547fc148ce3fcc8a347bfb37c54..01bade85cdfff48a3d327b6227d1441fd1326b47 100644 (file)
@@ -14076,7 +14076,7 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain)
 
                 /* Zero-length parameter packs are boring. Just substitute
                    into the chain.  */
-                if (len == 0)
+               if (len == 0 && !cp_unevaluated_operand)
                   RETURN (tsubst (TREE_CHAIN (t), args, complain,
                                  TREE_CHAIN (t)));
               }
diff --git a/gcc/testsuite/g++.dg/cpp0x/variadic-parm1.C b/gcc/testsuite/g++.dg/cpp0x/variadic-parm1.C
new file mode 100644 (file)
index 0000000..4300c78
--- /dev/null
@@ -0,0 +1,17 @@
+// PR c++/93140
+// { dg-do compile { target c++11 } }
+
+int
+bar ()
+{
+  return 42;
+}
+
+template <typename... R>
+void foo (R... r, decltype (bar (r...)) x = 0) {}
+
+int
+main ()
+{
+  foo (3);
+}