看起来is_nothrow_constructible_v()在MSVC中被破坏了,我错了吗
Looks like is_nothrow_constructible_v() is broken in MSVC, am I wrong?
编辑:这里有更好的代码可以重现。所有低于19.20的MSVC版本都无法编译测试。
此问题与此SO帖子有关。我注意到当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; }
如果我用MSVC v15.9.20构建并运行它——进程得到std::terminate()
d。看起来问题出在_Construct_in_place()
:中
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>)
看起来is_nothrow_constructible_v<S, inplacer<...>>
会产生假阳性,从而导致noexcept
声明,这反过来又会在底层代码抛出时杀死我的应用程序。
p.S.GCC和Clang似乎工作得很好。
这是一个已知的错误。已在msvc v19.16中修复。
相关文章:
- #定义c-预处理器常量..我做错了什么
- 努力将整数转换为链表。不知道我在这里做错了什么
- 看起来is_nothrow_constructible_v()在MSVC中被破坏了,我错了吗
- .h 和.cpp文件分离时出错,但仅使用 .h 文件时没有错误.我做错了什么?
- 我的C++线程做错了什么?
- 谁能告诉我我用 getline 做错了什么 (cpp) 格式
- 没有输出的合并排序我做错了什么?
- 我正在尝试使用 while 循环从字符串中删除字母,直到没有字母。我在这里做错了什么?
- 在C++中使用 AKS 素数测试计算双胞胎素数 我做错了什么?
- 指针相关的UE4崩溃.我的指针哪里错了?
- 我一直试图弄清楚我在这个链表程序中做错了什么
- 我正在尝试学习如何在 c++ 中传递指针,但出现错误:没有用于调用"test"的匹配函数。我做错了什么?
- FFMPEG,C++,内存泄漏,我做错了什么?
- 理解C++内存顺序,我错了吗?
- 为什么C++数组索引值是有符号的,而不是围绕size_t类型构建的(或者我错了)
- SFML sf::Text::setFillColor 坏了,还是我做错了什么
- CUDA 优化此代码很糟糕还是我错了?
- 带有WH_KEYBOARD的SetWindowsHookEx对我不起作用,我错了什么?
- 在C++中声明指向结构的指针会自动为其成员分配内存.我错了吗
- 我一直在复制一个给定地址的类,我错了