Skip to content

Commit 67066b8

Browse files
committed
Maybe fix MSVC + CUDA builds
The MSVC build failure on the previous commit looks like a misplaced `[[no_unique_address]]`; the CUDA build failures are mysterious to me, but they appear to be downstream of changing `__any`'s `__box` type to use in-place new into an uninitialized member of an anonymous union, which I did to address a GCC build failure. This diff makes the anonymous union hack GCC-specific, to hopefull make all the compilers happy at the expense of preprocessor complexity.
1 parent 83dfbdc commit 67066b8

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

include/stdexec/__detail/__any.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,11 +465,25 @@ namespace STDEXEC::__any
465465
: __val_(static_cast<_Args &&>(__args)...)
466466
{}
467467

468+
#if !STDEXEC_GCC()
468469
template <class _Fn, class... _Args>
469470
constexpr explicit __box(__in_place_from_t, _Fn &&__fn, _Args &&...__args)
470471
noexcept(__nothrow_callable<_Fn, _Args...>)
472+
: __val_(static_cast<_Fn &&>(__fn)(static_cast<_Args &&>(__args)...))
471473
{
472474
static_assert(__same_as<__call_result_t<_Fn, _Args...>, _Value>);
475+
}
476+
#else
477+
template <class _Fn, class... _Args>
478+
constexpr explicit __box(__in_place_from_t, _Fn &&__fn, _Args &&...__args)
479+
noexcept(__nothrow_callable<_Fn, _Args...>)
480+
{
481+
// for unknown reasons, GCC (sometimes) doesn't like initializing __val_ with the
482+
// result of this function call in the member initialization clause when _Value
483+
// is immovable even though the conditions should be right to trigger C++17's
484+
// mandatory copy elision, but this in-place new into an uninitialized anonymous
485+
// union member works just fine
486+
static_assert(__same_as<__call_result_t<_Fn, _Args...>, _Value>);
473487
new ((void *) std::addressof(__val_))
474488
_Value(static_cast<_Fn &&>(__fn)(static_cast<_Args &&>(__args)...));
475489
}
@@ -502,6 +516,7 @@ namespace STDEXEC::__any
502516
__val_ = __rhs.__val_;
503517
return *this;
504518
}
519+
#endif
505520

506521
template <class _Self>
507522
[[nodiscard]]
@@ -511,11 +526,16 @@ namespace STDEXEC::__any
511526
}
512527

513528
private:
529+
#if !STDEXEC_GCC()
514530
STDEXEC_ATTRIBUTE(no_unique_address)
531+
_Value __val_;
532+
#else
515533
union
516534
{
535+
STDEXEC_ATTRIBUTE(no_unique_address)
517536
_Value __val_;
518537
};
538+
#endif
519539
};
520540

521541
template <class _Interface, __box_kind _BoxKind>

0 commit comments

Comments
 (0)