Skip to content

<generator>: Don't use operator new[] and operator delete[] #4621

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions stl/inc/generator
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private:
}

static void __stdcall _Dealloc_delete(void* const _Ptr, const size_t _Size) noexcept {
::operator delete[](_Ptr, _Size + sizeof(_Dealloc_fn));
::operator delete(_Ptr, _Size + sizeof(_Dealloc_fn));
}

template <class _ProtoAlloc>
Expand Down Expand Up @@ -164,7 +164,7 @@ private:

public:
static void* operator new(const size_t _Size) { // default: new/delete
void* const _Ptr = ::operator new[](_Size + sizeof(_Dealloc_fn));
void* const _Ptr = ::operator new(_Size + sizeof(_Dealloc_fn));
const _Dealloc_fn _Dealloc = _Dealloc_delete;
_CSTD memcpy(static_cast<char*>(_Ptr) + _Size, &_Dealloc, sizeof(_Dealloc_fn));
return _Ptr;
Expand Down
10 changes: 10 additions & 0 deletions tests/std/tests/P2502R2_generator_promise/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@

using namespace std;

#pragma warning(disable : 28251) // Inconsistent annotation for 'new[]': this instance has no annotations.

void* operator new[](size_t) {
unreachable();
}

void operator delete[](void*) noexcept {
unreachable();
}

template <class Promise, class... Args>
concept HasOperatorNew = requires(Args&&... args) {
{ Promise::operator new(forward<Args>(args)...) } -> same_as<void*>;
Expand Down