Skip to content

Commit

Permalink
defeat gcc's (over?) eager optimizer with std::launder
Browse files Browse the repository at this point in the history
  • Loading branch information
ericniebler committed Nov 2, 2023
1 parent da9815f commit 4db236c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions include/stdexec/__detail/__memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <memory>
#include <new>
#include <utility> // for std::launder

namespace stdexec {
namespace __mem {
Expand Down Expand Up @@ -63,22 +64,22 @@ namespace stdexec {
auto __alloc = _GetAllocator(__data);
_Derived* __ptr = __alloc.__allocate();
[[maybe_unused]] __scope_guard __g{[&]() noexcept { __alloc.__deallocate(__ptr); }};
::new(&__ptr->__data_) _Data((_Data&&) __data);
::new(&std::launder(__ptr)->__data_) _Data((_Data&&) __data);
__g.__dismiss();
return __ptr;
}

static void operator delete(void* __self, _Data&&) {
_Derived* __ptr = static_cast<_Derived*>(__self);
auto __alloc = _GetAllocator(__ptr->__data_);
__ptr->__data_.~_Data();
std::launder(__ptr)->__data_.~_Data();
__alloc.__deallocate(__ptr);
}

static void operator delete(__with_allocator_provider* __self, std::destroying_delete_t) noexcept {
_Derived* __ptr = static_cast<_Derived*>(__self);
auto __alloc = _GetAllocator(__ptr->__data_);
__ptr->__data_.~_Data();
std::launder(__ptr)->__data_.~_Data();
__alloc.__destroy(__ptr);
__alloc.__deallocate(__ptr);
}
Expand Down

0 comments on commit 4db236c

Please sign in to comment.