Bug 95434 - ICE for CTAD in generic lambda within variadic lambda
Summary: ICE for CTAD in generic lambda within variadic lambda
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 10.1.0
: P3 normal
Target Milestone: 10.4
Assignee: Patrick Palka
URL: https://godbolt.org/z/-fZVX4
Keywords: c++-lambda, ice-on-valid-code
Depends on:
Blocks: lambdas
  Show dependency treegraph
 
Reported: 2020-05-30 05:34 UTC by Johel Ernesto Guerrero Peña
Modified: 2022-03-11 00:32 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work: 11.0
Known to fail: 10.1.0
Last reconfirmed: 2020-07-14 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Johel Ernesto Guerrero Peña 2020-05-30 05:34:30 UTC
The following snippet ICEs. See https://godbolt.org/z/-fZVX4.
```C++
template <class T> struct type { T value; };
template <class T> type(T) -> type<T>;
void f()
{
    []<template <class> class... Ts>()
    {
        (..., []<template <class> class T>() {
            T{0};
        }.template operator()<Ts>());
    }
    .template operator()<type>();
}

```
Comment 1 Johel Ernesto Guerrero Peña 2020-05-30 05:41:36 UTC
Perhaps it's related to the following snippet that errors. I don't see why it shouldn't work. Should I open a separate bug report on this?
```C++
template <template <class> class... Ts>
void g()
{
    (..., Ts{0}); // error: operand of fold expression has no unexpanded parameter packs
}
```
Comment 2 Patrick Palka 2020-07-14 20:59:09 UTC
Confirmed.  Fails on trunk, too.
Comment 3 Johel Ernesto Guerrero Peña 2020-08-12 00:51:20 UTC
Another example: https://godbolt.org/z/Wq1vjP. Perhaps, this too requires another bug report.
```C++
template <template <class> class T, class... Us>
concept ctadable = requires(Us... us) { T{us...}; };

template <class T>
struct X { T x; };

static_assert(ctadable<X, int>);
```
Comment 4 Patrick Palka 2021-01-19 15:08:28 UTC
Looks like the testcases in comment #1 and comment #3 are PR98611 and are fixed for GCC 11 with r11-6614.

We still ICE on your original testcase though.  Reduced:

template <class>
void f() {
  []<template <class> class U>() { U{0}; };
}

template void f<int>();
Comment 5 GCC Commits 2021-01-20 14:55:29 UTC
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:cafcfcb5840b62d9fc80c12192189351e995a4f2

commit r11-6816-gcafcfcb5840b62d9fc80c12192189351e995a4f2
Author: Patrick Palka <ppalka@redhat.com>
Date:   Wed Jan 20 09:44:33 2021 -0500

    c++: Fix tsubsting CLASS_PLACEHOLDER_TEMPLATE [PR95434]
    
    Here, during partial instantiation of the generic lambda, we do
    tsubst_copy on the CLASS_PLACEHOLDER_TEMPLATE for U{0} which yields a
    (level-lowered) TEMPLATE_TEMPLATE_PARM rather than the corresponding
    TEMPLATE_DECL.  This later confuses do_class_deduction which expects
    that a CLASS_PLACEHOLDER_TEMPLATE is always a TEMPLATE_DECL.
    
    gcc/cp/ChangeLog:
    
            PR c++/95434
            * pt.c (tsubst) <case TEMPLATE_TYPE_PARM>: If tsubsting
            CLASS_PLACEHOLDER_TEMPLATE yields a TEMPLATE_TEMPLATE_PARM,
            adjust to its TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL.
    
    gcc/testsuite/ChangeLog:
    
            PR c++/95434
            * g++.dg/cpp2a/lambda-generic9.C: New test.
Comment 6 Johel Ernesto Guerrero Peña 2021-02-03 05:43:03 UTC
Thank you.
Comment 7 GCC Commits 2021-04-20 16:09:12 UTC
The releases/gcc-10 branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:2400f81c2c2489f4b6fbb245ef946a39be40defd

commit r10-9734-g2400f81c2c2489f4b6fbb245ef946a39be40defd
Author: Patrick Palka <ppalka@redhat.com>
Date:   Tue Apr 20 12:06:27 2021 -0400

    c++: Fix tsubsting CLASS_PLACEHOLDER_TEMPLATE [PR95434]
    
    Here, during partial instantiation of the generic lambda, we do
    tsubst_copy on the CLASS_PLACEHOLDER_TEMPLATE for U{0} which yields a
    (level-lowered) TEMPLATE_TEMPLATE_PARM rather than the corresponding
    TEMPLATE_DECL.  This later confuses do_class_deduction which expects
    that a CLASS_PLACEHOLDER_TEMPLATE is always a TEMPLATE_DECL.
    
    gcc/cp/ChangeLog:
    
            PR c++/95434
            * pt.c (tsubst) <case TEMPLATE_TYPE_PARM>: If tsubsting
            CLASS_PLACEHOLDER_TEMPLATE yields a TEMPLATE_TEMPLATE_PARM,
            adjust to its TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL.
    
    gcc/testsuite/ChangeLog:
    
            PR c++/95434
            * g++.dg/cpp2a/lambda-generic9.C: New test.
    
    (cherry picked from commit cafcfcb5840b62d9fc80c12192189351e995a4f2)