Date: Fri, 16 Jun 2023 14:28:20 -0700
Hi all,
We noticed that the C++11 spec guarantees that std::atomic<bool> has a
trivial constructor and a trivial destructor, but these three guarantees
were lost in the C++17 spec and onward.
----------
C++11:
(§29.5) 4. … There shall be a specialization atomic<bool> which
provides the general atomic operations as specified in 29.6.1.
(§29.5) 5. The atomic integral specializations and the
specialization atomic<bool> shall have standard layout. They shall each
have a trivial default constructor and a trivial destructor. They shall
each support aggregate initialization syntax.
----------
C++17:
(§32.6) 2. The specialization atomic<bool> is a standard-layout
struct.
(§32.6.2 ) 1. … [ Note: For the specialization atomic<bool>, see
32.6. — end note ]
----------
The change occurred in P0558
<https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0558r1.pdf>, and
as far as we can tell, was not intentional. A brief experiment using
godbolt.org <https://godbolt.org/z/EGqrrn7h7> shows that std::atomic<bool>
is indeed trivially constructible and trivially destructible on the current
versions of all listed compilers.
Is this a defect in the current spec? Thanks!
--Jeremy Hurwitz & Matt Maly
We noticed that the C++11 spec guarantees that std::atomic<bool> has a
trivial constructor and a trivial destructor, but these three guarantees
were lost in the C++17 spec and onward.
----------
C++11:
(§29.5) 4. … There shall be a specialization atomic<bool> which
provides the general atomic operations as specified in 29.6.1.
(§29.5) 5. The atomic integral specializations and the
specialization atomic<bool> shall have standard layout. They shall each
have a trivial default constructor and a trivial destructor. They shall
each support aggregate initialization syntax.
----------
C++17:
(§32.6) 2. The specialization atomic<bool> is a standard-layout
struct.
(§32.6.2 ) 1. … [ Note: For the specialization atomic<bool>, see
32.6. — end note ]
----------
The change occurred in P0558
<https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0558r1.pdf>, and
as far as we can tell, was not intentional. A brief experiment using
godbolt.org <https://godbolt.org/z/EGqrrn7h7> shows that std::atomic<bool>
is indeed trivially constructible and trivially destructible on the current
versions of all listed compilers.
Is this a defect in the current spec? Thanks!
--Jeremy Hurwitz & Matt Maly
Received on 2023-06-16 21:28:34