Coroutines and variadic arguments

Viewed 245

The first restriction on coroutines specified in cpp reference page is that coroutines cannot use variadic arguments. But when I try to use a coroutine that accepts varidaic arguments in its parameter list, for e.g.:

template<typename ...Args>
ReturnObject coro_with_variadic_argument1(Args ...args){
    std::cout << "size of variadic args: " << sizeof...(args) << "\n";
    co_await std::suspend_never{};
}

it works fine in GCC-11, Clang-14 and only MSVC-19 gives some sort warnings which doesn't seem to have anything to do with coroutines and varidaic arguments, and prints the output after the warning. See the code on compiler explorer. So what exactly does the cppreference page mean by the statement:

Coroutines cannot use variadic arguments ...

Is there an example where creating C++ coroutines with variadic arguments is illegal ?

1 Answers

As mentioned in the comment by cigien, I confused variadic arguments with template parameter packs.

So the following will be an illegal coroutine:

ReturnObject coro_with_variadic_argument1(...) // <-- note variadic arg here 
{
    co_await std::suspend_never{}; 
}
Related