I am trying to compile the following code in Visual Studio 2017:
#include <future>
int main()
{
std::promise<std::reference_wrapper<int>> promise;
(void)promise;
}
However, I get the following error:
error C2512: 'std::reference_wrapper': no appropriate default constructor available
Whereas it compiles fine with GCC and Clang.
Is this is a definite bug in Visual Studio or is it a valid implementation of std::promise?
For detailed information, see C++ Conformance Improvements in Visual Studio 2017. The compiler supports about 75% of the features that are new in C++17, including structured bindings, constexpr lambdas, if constexpr, inline variables, fold expressions, and adding noexcept to the type system. These features are available under the /std:c++17 option.
Visual Studio 2017 allows using /sdl with /await. We removed the /RTC limitation with Coroutines. /std:c++14 and /std:c++latest: These compiler options enable you to opt in to specific versions of the ISO C++ programming language in a project.
This warning is off by default in Visual Studio 2017 version 15.3, and only impacts code compiled with /Wall /WX. Starting in Visual Studio 2017 version 15.5, it's enabled by default as a level 3 warning.
With support for generalized constexpr and non-static data member initialization (NSDMI) for aggregates, the MSVC compiler in Visual Studio 2017 is now complete for features added in the C++14 standard. However, the compiler still lacks a few features from the C++11 and C++98 standards.
Looks like it is a known issue in MSVC's standard library implementation. A simpler reproduction scenario:
#include <future>
struct NoDefaultCtor
{
NoDefaultCtor() = delete;
};
int main() {
std::promise<NoDefaultCtor> p;
return 0;
}
I suppose you do not need std::reference_wrapper<int>
. There is the suitable overloaded template for std::promise
available:
template<class R> class promise<R&>;
Therefore you can fix your code in Visual Studio 2017:
#include <future>
int main()
{
std::promise<int&> promise;
(void)promise;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With