landelare / ue5coro

A C++20 coroutine implementation for Unreal Engine 5 that feels almost native.
BSD 3-Clause Clear License
543 stars 48 forks source link

Compile error : A coroutine cannot have a return type containing 'auto' #12

Closed ameaninglessname closed 1 year ago

ameaninglessname commented 1 year ago

Using Visual Studio 2022 14.35.32217 toolchain (C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.35.32215) and Windows 10.0.22621.0 SDK (C:\Program Files (x86)\Windows Kits\10).

Error C7617 : 'SetupPlayerInputComponent::::operator ()': A coroutine cannot have a return type containing 'auto'

[C7617] Please use '/await' command-line option to enable relevant extensions

I got this error when trying to capture variable in the coroutine lambda:

auto LoadingLambda = [This{this}]()
{
    auto Coroutine = [WeakThis = FWeakObjectPtr{This}] -> UE5Coro::TCoroutine<>
    {
        // co_await something

        // validate WeakThis

        co_return;
    };
    Coroutine();
};

After changing it to this, it compiles fine:

auto LoadingLambda = [This{this}]()
{
    auto Coroutine = [This] -> UE5Coro::TCoroutine<>
    {
        FWeakObjectPtr WeakThis{This};

        // co_await something

        // validate WeakThis

        co_return;
    };
    Coroutine();
};

but still get a warning from rider: image

landelare commented 1 year ago

Your code has multiple errors. You're trying to capture [this] from within a nested lambda that's already "lost" this due to LoadingLambda having no captures, and the mandatory () is missing before the -> return type specification. With these issues fixed, I managed to compile a similar nested lambda setup on both MSVC and Clang.

I can't do anything about Rider's tooltips, try reporting this issue to them.

ameaninglessname commented 1 year ago

My bad for over simplified the example code.(Fixed.)

I tried really hard to find reproducible steps, but i failed. It looks like a compiler error. I decide to work around and ignore it now. (Just about to close this when you just closed it^^)