https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86969

            Bug ID: 86969
           Summary: [Regression] ICE (in tsubst_copy) for a generic
                    recursive lambda
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: v.reshetnikov at gmail dot com
  Target Milestone: ---

/************************* BEGIN SOURCE *************************/
auto compose = [](auto... fs) {
    if constexpr (sizeof...(fs) == 0) {
        return [](auto x) { return x; };
    } else {
        auto fn = [](auto self, auto f, auto... fs) {
            if constexpr (sizeof...(fs) == 0) return f;
            else return [=](auto x) { 
                return f(self(self, fs...)(x));
            };
        };
        return fn(fn, fs...);
    }
};

static_assert(compose(
        [](auto x) { return x * 3; },
        [](auto x) { return x + 1; },
        [](auto x) { return x / 2; }
    )(6) == 12);

/************************** END SOURCE **************************/

EXPECTED: no errors.

ACTUAL:

<source>: In instantiation of '<lambda(auto:1 ...)> [with auto:1 =
{<lambda(auto:7)>, <lambda(auto:8)>, <lambda(auto:9)>}]::<lambda(auto:3,
auto:4, auto:5 ...)> [with auto:3 = <lambda(auto:1 ...)> [with auto:1 =
{<lambda(auto:7)>, <lambda(auto:8)>, <lambda(auto:9)>}]::<lambda(auto:3,
auto:4, auto:5 ...)>; auto:4 = <lambda(auto:7)>; auto:5 = {<lambda(auto:8)>,
<lambda(auto:9)>}]':
<source>:11:18:   required from '<lambda(auto:1 ...)> [with auto:1 =
{<lambda(auto:7)>, <lambda(auto:8)>, <lambda(auto:9)>}]'
<source>:19:5:   required from here
<source>:8:30: internal compiler error: in tsubst_copy, at cp/pt.c:15348
8 |                 return f(self(self, fs...)(x));
  |                          ~~~~^~~~~~~~~~~~~

Compiles successfully with 7.3, fails with 8.1 and newer. Compiles successfully
with Clang. Looks similar to Bug 86926, but ICE location is different.

Reply via email to