In the following program foo
function is executed asynchronously and its argument of type A
is copied inside async
by value:
#include <future>
struct A {
A() = default;
explicit A(const A &) = default;
};
void foo(const A &) {}
int main() {
auto f = std::async(std::launch::async, foo, A{});
}
Despite copy-constructor of A
is explicit, the program is accepted in the latest MSVC and in libstdc++ from GCC 10. But starting from GCC 11 the program is rejected with the
error: could not convert '{std::forward<void (&)(const A&)>((* & __args#0)), std::forward<A>((* & __args#1))}' from '<brace-enclosed initializer list>' to 'std::tuple<void (*)(const A&), A>'
1693 | _M_fn{{std::forward<_Args>(__args)...}}
Online demo: https://gcc.godbolt.org/z/r3PsoaxT7
Is GCC 11 more correct here or it is a regression?