Opened 10 years ago

Closed 8 years ago

#8158 closed Bugs (fixed)

atomic_flag default constructor is not trivial

Reported by: Andrey Semashev Owned by: timblechmann
Milestone: To Be Determined Component: atomic
Version: Boost 1.53.0 Severity: Problem
Keywords: Cc:

Description

The current implementation of atomic_flag has non-trivial default constructor that initializes the flag to the non-signalled state. This contradicts the standard which requires the default constructor to be trivial, leaving the flag uninitialized. The flag should be initialized with the ATOMIC_FLAG_INIT macro, which is not currently provided by Boost.Atomic.

The atomic_flag interface should be as close as possible to C++11, which would improve portability.

Change History (1)

comment:1 by Andrey Semashev, 8 years ago

Resolution: fixed
Status: newclosed

Fixed in git develop and master, will be released in 1.56.

The default constructor of atomic_flag cannot be trivial in C++03 because the copy constructor has to be declared private (to prohibit copying). With a C++11 compiler the implementation now defines a constexpr constructor which basically provides the same guarantees as the trivial constructor would have. Also, BOOST_ATOMIC_FLAG_INIT is provided in this case.

Note: See TracTickets for help on using tickets.