更新时间:2023-11-10 23:03:40
As mentioned in P0883, the main reason for this behavior is compatibility with C. Obviously C has no notion of value initialization; atomic_int i;
performs no initialization. To be compatible with C, the C++ equivalent must also perform no initialization. And since atomic_int
in C++ is supposed to be an alias for std::atomic<int>
, then for full C/C++ compatibility, that type too must perform no initialization.
幸运的是, C ++ 20似乎正在消除这种行为.