Skip to content

Commit 8b7c2f6

Browse files
committed
Fix GCC builds
I don't know why GCC needs this change, but using in-place `new` to initialize a member of an anonymous union with the result of a function call rather than directly initializing the same value in the member initialization clause from the same function allows GCC to recognize that initializing the value with a prvalue does not invoke the move constructor.
1 parent cecea41 commit 8b7c2f6

2 files changed

Lines changed: 38 additions & 2 deletions

File tree

include/stdexec/__detail/__any.hpp

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,9 +467,39 @@ namespace STDEXEC::__any
467467
template <class _Fn, class... _Args>
468468
constexpr explicit __box(__in_place_from_t, _Fn &&__fn, _Args &&...__args)
469469
noexcept(__nothrow_callable<_Fn, _Args...>)
470-
: __val_(static_cast<_Fn &&>(__fn)(static_cast<_Args &&>(__args)...))
471470
{
472471
static_assert(__same_as<__call_result_t<_Fn, _Args...>, _Value>);
472+
new ((void *) std::addressof(__val_))
473+
_Value(static_cast<_Fn &&>(__fn)(static_cast<_Args &&>(__args)...));
474+
}
475+
476+
constexpr __box(__box &&__other) noexcept(__nothrow_move_constructible<_Value>)
477+
requires __std::move_constructible<_Value>
478+
: __val_(static_cast<_Value &&>(__other).__val_)
479+
{}
480+
481+
constexpr __box(__box const &__other) noexcept(__nothrow_copy_constructible<_Value>)
482+
requires __std::copy_constructible<_Value>
483+
: __val_(__other.__val_)
484+
{}
485+
486+
constexpr ~__box()
487+
{
488+
__val_.~_Value();
489+
}
490+
491+
constexpr __box &operator=(__box &&__rhs) noexcept(__nothrow_move_assignable<_Value>)
492+
requires __move_assignable<_Value>
493+
{
494+
__val_ = static_cast<__box &&>(__rhs).__val_;
495+
return *this;
496+
}
497+
498+
constexpr __box &operator=(__box const &__rhs) noexcept(__nothrow_copy_assignable<_Value>)
499+
requires __copy_assignable<_Value>
500+
{
501+
__val_ = __rhs.__val_;
502+
return *this;
473503
}
474504

475505
template <class _Self>
@@ -481,7 +511,10 @@ namespace STDEXEC::__any
481511

482512
private:
483513
STDEXEC_ATTRIBUTE(no_unique_address)
484-
_Value __val_;
514+
union
515+
{
516+
_Value __val_;
517+
};
485518
};
486519

487520
template <class _Interface, __box_kind _BoxKind>

include/stdexec/__detail/__concepts.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,9 @@ namespace STDEXEC
304304
template <class _Ty, class _A>
305305
concept __nothrow_assignable_from = STDEXEC_IS_NOTHROW_ASSIGNABLE(_Ty, _A);
306306

307+
template <class... _Ts>
308+
concept __move_assignable = (__assignable_from<_Ts, _Ts> && ...);
309+
307310
template <class... _Ts>
308311
concept __nothrow_move_assignable = (__nothrow_assignable_from<_Ts, _Ts> && ...);
309312

0 commit comments

Comments
 (0)