C++ 看起来MSVC中没有可构造的,我错了吗?
编辑:更好地复制代码。所有低于19.20的MSVC版本都无法编译测试C++ 看起来MSVC中没有可构造的,我错了吗?,c++,visual-c++,c++17,C++,Visual C++,C++17,编辑:更好地复制代码。所有低于19.20的MSVC版本都无法编译测试 这一问题与环境有关。我注意到当inplacer下的逻辑抛出异常时,我的应用程序被终止 下面是要复制的代码: #include <optional> struct S{}; S foo() { throw "oh, noes..."; } template<class F> struct inplacer { F f_; operator std::invoke_
这一问题与环境有关。我注意到当
inplacer
下的逻辑抛出异常时,我的应用程序被终止
下面是要复制的代码:
#include <optional>
struct S{};
S foo() { throw "oh, noes..."; }
template<class F>
struct inplacer
{
F f_;
operator std::invoke_result_t<F&>() { return f_(); }
};
template<class F> inplacer(F) -> inplacer<F>;
int main()
try
{
std::optional<S> v;
v.emplace( inplacer{ []{ return foo(); } } );
return 0;
}
catch(...) { return 1; }
看起来,is\u nothrow\u constructible\u v
会产生误报,从而导致noexcept
声明,当底层代码抛出时,这反过来会杀死我的应用程序
另外,GCC和Clang似乎运作良好。这是一个好办法。已在msvc v19.16中修复
template<class _Ty,
class... _Types> inline
void _Construct_in_place(_Ty& _Obj, _Types&&... _Args)
_NOEXCEPT_COND(is_nothrow_constructible_v<_Ty, _Types...>) <----- HERE???
{ // invoke True Placement New to initialize the referenced object with _Args...
::new (const_cast<void *>(static_cast<const volatile void *>(_STD addressof(_Obj))))
_Ty(_STD forward<_Types>(_Args)...);
}
// std::_Construct_in_place<S,inplacer<S <lambda>(void) > >(S & _Obj, inplacer<S <lambda>(void) > && <_Args_0>)