为什么 std::atomic 在视觉C++中不是简单的类型?



Folly 库要求std::atomic<hazptr_obj*>应该是一个普通类型。这适用于 gcc 和 clang,但对于视觉C++甚至对于std::atomic<int>也失败了。为什么std::is_trivial返回false

#include <type_traits>
#include <atomic>
static_assert(
std::is_trivial<std::atomic<int>>::value,
"std::atomic<int> not trivial");

std::atomic曾经是微不足道的(这需要琐碎可复制),但现在不是了。请参阅此答案,以获取有关其如何以及为何更改的出色而详细的解释。

这使得至少在 C++17 中符合 VC 标准,而 gcc 和 clang 不合规。由于委员会认为这是一个缺陷,VC也显示了C++11和C++14的预期行为。

为了将来参考,相关缺陷是DR #1734,您可以在此处查看clang的实现状态。我不知道 gcc 的等效状态页面。

folly中的断言在 https://github.com/facebook/folly/commit/a47a5531edcb95a27f987e810272ba94a9b51162 中为 MSVC 禁用

最新更新