Skip to content

Commit 2e3d7d4

Browse files
committed
default construct translated atomic without SFINAE
1 parent b45ed21 commit 2e3d7d4

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/hotspot/share/runtime/atomic.hpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -512,17 +512,18 @@ class AtomicImpl::Atomic<T, AtomicImpl::Category::Translated>
512512
static Decayed decay(T x) { return Translator::decay(x); }
513513
static T recover(Decayed x) { return Translator::recover(x); }
514514

515+
// Support for default construction via the default construction of _value.
516+
struct UseDecayedCtor {};
517+
explicit Atomic(UseDecayedCtor) : _value() {}
518+
using DefaultCtorSelect =
519+
std::conditional_t<std::is_default_constructible_v<T>, T, UseDecayedCtor>;
520+
515521
public:
516522
using ValueType = T;
517523

518524
// If T is default constructible, construct from a default constructed T.
519-
template<typename Dep = T, ENABLE_IF(std::is_default_constructible_v<Dep>)>
520-
Atomic() : Atomic(T()) {}
521-
522-
// If T is not default constructible, default construct the underlying
523-
// Atomic<Decayed>.
524-
template<typename Dep = T, ENABLE_IF(!std::is_default_constructible_v<Dep>)>
525-
Atomic() : _value() {}
525+
// Otherwise, default construct the underlying Atomic<Decayed>.
526+
Atomic() : Atomic(DefaultCtorSelect()) {}
526527

527528
explicit Atomic(T value) : _value(decay(value)) {}
528529

0 commit comments

Comments
 (0)