Skip to content

Commit 7ad2c73

Browse files
<generator>: Don't use operator new[] and operator delete[] (#4621)
1 parent c2b0579 commit 7ad2c73

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

stl/inc/generator

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ private:
128128
}
129129

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

134134
template <class _ProtoAlloc>
@@ -164,7 +164,7 @@ private:
164164

165165
public:
166166
static void* operator new(const size_t _Size) { // default: new/delete
167-
void* const _Ptr = ::operator new[](_Size + sizeof(_Dealloc_fn));
167+
void* const _Ptr = ::operator new(_Size + sizeof(_Dealloc_fn));
168168
const _Dealloc_fn _Dealloc = _Dealloc_delete;
169169
_CSTD memcpy(static_cast<char*>(_Ptr) + _Size, &_Dealloc, sizeof(_Dealloc_fn));
170170
return _Ptr;

tests/std/tests/P2502R2_generator_promise/test.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <coroutine>
66
#include <cstddef>
77
#include <cstdint>
8+
#include <cstdlib>
89
#include <forward_list>
910
#include <generator>
1011
#include <list>
@@ -22,6 +23,16 @@
2223

2324
using namespace std;
2425

26+
#pragma warning(disable : 28251) // Inconsistent annotation for 'new[]': this instance has no annotations.
27+
28+
void* operator new[](size_t) {
29+
abort();
30+
}
31+
32+
void operator delete[](void*) noexcept {
33+
abort();
34+
}
35+
2536
template <class Promise, class... Args>
2637
concept HasOperatorNew = requires(Args&&... args) {
2738
{ Promise::operator new(forward<Args>(args)...) } -> same_as<void*>;

0 commit comments

Comments
 (0)