]> gcc.gnu.org Git - gcc.git/commitdiff
c++: lambda in pack expansion [PR115378]
authorPatrick Palka <ppalka@redhat.com>
Fri, 7 Jun 2024 16:12:30 +0000 (12:12 -0400)
committerPatrick Palka <ppalka@redhat.com>
Fri, 7 Jun 2024 16:12:30 +0000 (12:12 -0400)
Here find_parameter_packs_r is incorrectly treating the 'auto' return
type of a lambda as a parameter pack due to Concepts-TS specific logic
added in r6-4517, leading to confusion later when expanding the pattern.

Since we intend on removing Concepts TS support soon anyway, this patch
fixes this by restricting the problematic logic with flag_concepts_ts.
Doing so revealed that add_capture was relying on this logic to set
TEMPLATE_TYPE_PARAMETER_PACK for the 'auto' type of an pack expansion
init-capture, which we now need to do explicitly.

PR c++/115378

gcc/cp/ChangeLog:

* lambda.cc (lambda_capture_field_type): Set
TEMPLATE_TYPE_PARAMETER_PACK on the auto type of an init-capture
pack expansion.
* pt.cc (find_parameter_packs_r) <case TEMPLATE_TYPE_PARM>:
Restrict TEMPLATE_TYPE_PARAMETER_PACK promotion with
flag_concepts_ts.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1y/decltype-auto-103497.C: Adjust expected diagnostic.
* g++.dg/template/pr95672.C: Likewise.
* g++.dg/cpp2a/lambda-targ5.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/lambda.cc
gcc/cp/pt.cc
gcc/testsuite/g++.dg/cpp1y/decltype-auto-103497.C
gcc/testsuite/g++.dg/cpp2a/lambda-targ5.C [new file with mode: 0644]
gcc/testsuite/g++.dg/template/pr95672.C

index 630cc4eade144211ff94c4408ba64706a12eabd3..0770417810e9756c73c2828cdfaa0317356cbecb 100644 (file)
@@ -223,7 +223,8 @@ lambda_capture_field_type (tree expr, bool explicit_init_p,
           outermost CV qualifiers of EXPR.  */
        type = build_reference_type (type);
       if (uses_parameter_packs (expr))
-       /* Stick with 'auto' even if the type could be deduced.  */;
+       /* Stick with 'auto' even if the type could be deduced.  */
+       TEMPLATE_TYPE_PARAMETER_PACK (auto_node) = true;
       else
        type = do_auto_deduction (type, expr, auto_node);
     }
index abbba7c6746e7f35911a4db9f4cf2b4a406c1876..607753ae6b7f43e26649aa9093fda20580a2424a 100644 (file)
@@ -3940,7 +3940,7 @@ find_parameter_packs_r (tree *tp, int *walk_subtrees, void* data)
         parameter pack (14.6.3), or the type-specifier-seq of a type-id that
         is a pack expansion, the invented template parameter is a template
         parameter pack.  */
-      if (ppd->type_pack_expansion_p && is_auto (t)
+      if (flag_concepts_ts && ppd->type_pack_expansion_p && is_auto (t)
          && TEMPLATE_TYPE_LEVEL (t) != 0)
        TEMPLATE_TYPE_PARAMETER_PACK (t) = true;
       if (TEMPLATE_TYPE_PARAMETER_PACK (t))
index cedd661710cd49fd8ae1bd5ad8a40aaba462e64e..4162361d14f60679a4529e10b6ff29bd5d2a303d 100644 (file)
@@ -1,7 +1,7 @@
 // PR c++/103497
 // { dg-do compile { target c++14 } }
 
-void foo(decltype(auto)... args);  // { dg-error "cannot declare a parameter with .decltype.auto.." }
+void foo(decltype(auto)... args);  // { dg-error "contains no parameter packs" }
 
 int main() {
   foo();
diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-targ5.C b/gcc/testsuite/g++.dg/cpp2a/lambda-targ5.C
new file mode 100644 (file)
index 0000000..efd4bb4
--- /dev/null
@@ -0,0 +1,15 @@
+// PR c++/115378
+// { dg-do compile { target c++20 } }
+
+struct tt {};
+
+template<class Slot, auto Tag = []{}>
+constexpr auto __counter = 1;
+
+template <class Child, int Counter>
+using _as_base = tt;
+
+template <class... Envs>
+struct env : _as_base<Envs, __counter<int>>... {};
+
+env<int> t;
index c752b4a2c085ac7f9821087ef74eb08c8e2896bf..d97b8db2e97a833339008f90df73ad622c50525a 100644 (file)
@@ -1,3 +1,3 @@
 // PR c++/95672
 // { dg-do compile { target c++14 } }
-struct g_class : decltype  (auto) ... {  }; // { dg-error "invalid use of pack expansion" }
+struct g_class : decltype  (auto) ... {  }; // { dg-error "contains no parameter packs" }
This page took 0.087592 seconds and 5 git commands to generate.