All of the the constructors for the various Atomic<T> types should be constexpr. This will ensure the initialization of a non-local atomic variable be constant initialization (C++17 6.6.2) if the (possibly defaulted) initial value is provided by a constant expression.
This simplifies the use of atomic variables. In the common case where the initial value is defaulted or proved by a constant expression, there is no need to worry about whether the variable will be dynamically initialized. While it's likely a compiler would reduce the dynamic initialization to constant initialization, making the constructors constexpr guarantees constant initialization with suitable arguments. Without such a guarantee of constant initialization one might wonder whether DeferredStatic or some other mechanism is needed, per the HotSpot Style Guide.
This simplifies the use of atomic variables. In the common case where the initial value is defaulted or proved by a constant expression, there is no need to worry about whether the variable will be dynamically initialized. While it's likely a compiler would reduce the dynamic initialization to constant initialization, making the constructors constexpr guarantees constant initialization with suitable arguments. Without such a guarantee of constant initialization one might wonder whether DeferredStatic or some other mechanism is needed, per the HotSpot Style Guide.
- links to
-
Review(master)
openjdk/jdk/28711