What's the default value for a std::atomic?

前端 未结 2 1828
孤城傲影
孤城傲影 2021-01-01 22:46

I find that in practice, with a variety of C++11/C++14 compilers, a std::atomic has an undefined initial value just as it would if it were a \"raw\" type. That

2条回答
  •  离开以前
    2021-01-01 23:28

    [atomics.types.generic]/5 says this about integral specializations:

    The atomic integral specializations and the specialization atomic shall have standard layout. They shall each have a trivial default constructor and a trivial destructor. They shall each support aggregate initialization syntax.

    Moreover, the primary template synopsis at the beginning of the same section normatively specifies the default constructor as:

    atomic() noexcept = default;
    

    The effects are defined in [atomic.types.operations]/4 as:

    Effects: leaves the atomic object in an uninitialized state.

提交回复
热议问题