Why MSVC C++ requires a default constructor in struct needed when returning from async?

Viewed 48

The following code complains error C2512: 'MyStruct': no appropriate default constructor available when trying to compile with MSVC. It works fine with clang

struct MyStruct{
    int val;
    explicit MyStruct(int v): val(v){}
};

int main()
{
    auto ret = std::async([](){MyStruct ms{50}; return ms;});
    std::cout << ret.get().val;

    return 0;
}

Where does it require in this code to invoke the default constructor?

0 Answers
Related