]> gcc.gnu.org Git - gcc.git/commitdiff
c++: pack init-capture of unresolved overload [PR102629]
authorJason Merrill <jason@redhat.com>
Tue, 26 Apr 2022 04:19:40 +0000 (00:19 -0400)
committerJason Merrill <jason@redhat.com>
Thu, 12 May 2022 20:14:46 +0000 (16:14 -0400)
Here we were failing to diagnose that the initializer for the capture pack
is an unresolved overload.  It turns out that the reason we didn't recognize
the deduction failure in do_auto_deduction was that the individual 'auto' in
the expansion of the capture pack was still marked as a parameter pack, so
we were deducing it to an empty pack instead of failing.

PR c++/102629

gcc/cp/ChangeLog:

* pt.c (gen_elem_of_pack_expansion_instantiation): Clear
TEMPLATE_TYPE_PARAMETER_PACK on auto.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/lambda-pack-init7.C: New test.

gcc/cp/pt.c
gcc/testsuite/g++.dg/cpp2a/lambda-pack-init7.C [new file with mode: 0644]

index c98acbec4817f9d986e216c383eca004dca9df0f..a8fa2347c8a5fd63ec72dc58fed3a024885fb7fa 100644 (file)
@@ -12642,7 +12642,13 @@ gen_elem_of_pack_expansion_instantiation (tree pattern,
     t = tsubst_expr (pattern, args, complain, in_decl,
                     /*integral_constant_expression_p=*/false);
   else
-    t = tsubst (pattern, args, complain, in_decl);
+    {
+      t = tsubst (pattern, args, complain, in_decl);
+      if (is_auto (t) && !ith_elem_is_expansion)
+       /* When expanding the fake auto... pack expansion from add_capture, we
+          need to mark that the expansion is no longer a pack.  */
+       TEMPLATE_TYPE_PARAMETER_PACK (t) = false;
+    }
 
   /*  If the Ith argument pack element is a pack expansion, then
       the Ith element resulting from the substituting is going to
diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-pack-init7.C b/gcc/testsuite/g++.dg/cpp2a/lambda-pack-init7.C
new file mode 100644 (file)
index 0000000..f3c3899
--- /dev/null
@@ -0,0 +1,18 @@
+// PR c++/102629
+// { dg-do compile { target c++20 } }
+
+template <class T> T&& forward(T&);
+template <class T> T&& forward(T&&);
+
+struct S {};
+
+template <typename... Args>
+void foo(Args&&... args) {
+  [...args = forward<Args> /*(args)*/] { // { dg-error "" }
+    [](auto...) { } (forward<Args>(args)...);
+  };
+}
+
+void bar( ) {
+  foo(S{});
+}
This page took 0.087689 seconds and 5 git commands to generate.