<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/141425>141425</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [Clang] ICE with std::function constructor parameter and auto lambda capturing another lambda using CTAD
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          MorganCaron
      </td>
    </tr>
</table>

<pre>
    This minimal example triggers an internal compiler error (ICE) on Clang.

```cpp
#include <tuple>
#include <functional>

template<class... Args>
struct StdTupleLike
{
 template<class... Args2>
    StdTupleLike(Args2...)
 {}
};

template<class... Args>
StdTupleLike(Args...) -> StdTupleLike<Args...>;



template<class>
struct StdFunctionLike;

template<class Ret, class... Args>
struct StdFunctionLike<Ret(Args...)>
{
    template<class U>
 StdFunctionLike(U u): func{u}
    {}

    void operator()(Args... args)
 {
        func(args...);
    }

    Ret (*func)(Args...);
};



template<class... Funcs>
using FunctionsTuple = StdTupleLike<Funcs...>; // or: using FunctionsTuple = std::tuple<Funcs...>;
using NoFunctions = FunctionsTuple<>;

template<class Functions = NoFunctions>
inline auto execute(const Functions& = {}) -> void
{}

#if 1
struct TestSuite
{
 inline explicit TestSuite(std::function<void(TestSuite &)> function) // ICE
 {
        function(*this);
    }
};
#elif 0
struct TestSuite
{
 inline explicit TestSuite(StdFunctionLike<void(TestSuite &)> function) // BUILD
    {
        function(*this);
    }
};
#else
template<class T>
struct TestSuite
{
    inline explicit TestSuite(T &&function) // BUILD
    {
        function(*this);
    }
};
#endif

auto _ = TestSuite{[](auto &) {
    auto _ = [] {
        auto print = []() -> void {};
        execute(FunctionsTuple{print});
    };
}};

int main()
{
 return 0;
}
```

Tested on:
```
clang version 21.0.0 (/opt/llvm-git/llvm-project fd8fb7148674456ce3fb338864c9aa9f576feb22)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /opt/llvm-git/bin
```

Replacing ``std::function<void(TestSuite &)>`` with a custom wrapper like ``StdFunctionLike<void(TestSuite &)>`` avoids the ICE.

Same goes for using a generic forwarding constructor ``template<class T> TestSuite(T&&)``.

This seems to be related to how auto lambdas and CTAD interact inside the TestSuite construction when ``std::function`` is involved.

This compiles and runs correctly on GCC and MSVC.

The issue is isolated here on Compiler Explorer: https://godbolt.org/z/Ko5rYcros

Could you confirm if this is a known issue, or if a fix is planned?

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy0V8-P4rgS_mvMpdQoOCGEAwdIN0-tN_MO08yT9jRykkrwjmNHttPN7F-_sh1CoOnRzq62xaFJ-fvq11cVw4zhjUTckOWOLB9nrLdHpTeflW6YzJlWclao6sfmcOQGWi55ywTgibWdQLCaNw1qA0wClxa1ZAJK1XZcoAbUWmkgNHvOnwhdg5KQCyabOYm27pNG4VN2nftKYy5L0VcIJM5t3wkk8dM7Q93L0nIlmRis0dZi2wlmkcR5KZgx8_kctrox4YCxui8tvNjq4Dg_8e_oYKsdibbwEZQGLABcA2nmrfP5nNC1O-B4Vo-e8JHEu78S0B3CwAcPJH669hfnZ3P8NNLfd3Kb7X4oVOD5IDL4gpbQHH5at2um3EMmYQ99CAUFeFdT-DoU85aKZl-h9wRbcG0lq10fiuloLpUN318Vr0B1qJlVmtDMAccwgLm4Ly0JEPfniWnGJuHuRg8T-i9owbNuA2J9k-Pupscfd9rlONSwN1w2cE7a-L4CiR9vm-whY5eB0D2he1DaVeZDDmMrEm9JvB1m5YZldP8_NYI97pqKxPlUW--ad42dcIUMuRRcIrDeKsATlr11fS2VNPYCJTT16KGlZ6W7jg7KOXfCzXoNi4v8DmjsS8_tZGYHl3jqBC_59AjNxpqc1wSJc--GZuMxIDQNsoXxFF2fi-521V0RhXNOIPbIzT0hjeqgMQpeQ_S303g_dL-WxO7r86fpHP2jTAze08XhakvcyQ_gpykeQgbpvxy9rHgdpOUl-s3r8BLHahdee25DOHuo6sTr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