@@ -148,6 +148,14 @@ inline constexpr bool rejects_arithmetic_for_boolean_or_character_v =
148148 is_arithmetic_operation_v<OpTag> &&
149149 (is_boolean_or_character_v<LhsRep> || is_boolean_or_character_v<RhsRep>);
150150
151+ template <typename T>
152+ auto atomic_ref_load (T const &value, std::memory_order order) noexcept -> T {
153+ // libc++ rejects std::atomic_ref<const T>; load through a non-mutating view.
154+ auto &mutable_value = const_cast <T &>(value);
155+ std::atomic_ref<T> ref (mutable_value);
156+ return ref.load (order);
157+ }
158+
151159} // namespace details
152160
153161// Default protocol specializations.
@@ -292,8 +300,7 @@ struct concurrency::handler<concurrency::fenced, void, CommonRep,
292300 using result_type = std::expected<CommonRep, ErrorPayload>;
293301
294302 static auto load (CommonRep const &value) noexcept -> CommonRep {
295- std::atomic_ref<CommonRep const > ref (value);
296- return ref.load (std::memory_order_seq_cst);
303+ return details::atomic_ref_load (value, std::memory_order_seq_cst);
297304 }
298305
299306 static auto store (CommonRep &value, CommonRep desired) noexcept -> void {
@@ -318,8 +325,7 @@ struct concurrency::handler<concurrency::fenced_relaxed, void, CommonRep,
318325 using result_type = std::expected<CommonRep, ErrorPayload>;
319326
320327 static auto load (CommonRep const &value) noexcept -> CommonRep {
321- std::atomic_ref<CommonRep const > ref (value);
322- return ref.load (std::memory_order_relaxed);
328+ return details::atomic_ref_load (value, std::memory_order_relaxed);
323329 }
324330
325331 static auto store (CommonRep &value, CommonRep desired) noexcept -> void {
@@ -344,8 +350,7 @@ struct concurrency::handler<concurrency::fenced_acq_rel, void, CommonRep,
344350 using result_type = std::expected<CommonRep, ErrorPayload>;
345351
346352 static auto load (CommonRep const &value) noexcept -> CommonRep {
347- std::atomic_ref<CommonRep const > ref (value);
348- return ref.load (std::memory_order_acquire);
353+ return details::atomic_ref_load (value, std::memory_order_acquire);
349354 }
350355
351356 static auto store (CommonRep &value, CommonRep desired) noexcept -> void {
0 commit comments