The Folly library requires that std::atomic<hazptr_obj*>
should be a trivial type. This works with gcc and clang, but failing for Visual C++ even for std::atomic<int>
. Why does std::is_trivial
return false
?
#include <type_traits>
#include <atomic>
static_assert(
std::is_trivial<std::atomic<int>>::value,
"std::atomic<int> not trivial");
Each instantiation and full specialization of the std::atomic template defines an atomic type. Objects of atomic types are the only C++ objects that are free from data races; that is, if one thread writes to an atomic object while another thread reads from it, the behavior is well-defined.
A trivially copyable class is a class that: has no non-trivial copy constructors, has no non-trivial move constructors, has no non-trivial copy assignment operators, has no non-trivial move assignment operators, and has a trivial destructor. Copy/move constructors in [class.copy]/12.
std::atomic
used to be trivial (which requires Trivially Copyable), but isn't anymore. See this answer for a great and detailed explanation for how and why that changed.
This makes VC compliant and gcc and clang non-compliant at least in C++17. As this was considered a defect by the committee, VC shows the desired behavior for C++11 and C++14, too.
For future reference, the relevant defect is DR #1734, you can see the implementation status for clang here. I'm not aware of an equivalent status page for gcc.
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