Skip to content

Commit 76c41da

Browse files
Implement LWG-3900 The allocator_arg_t overloads of generator::promise_type::operator new should not be constrained (#5150)
Co-authored-by: Casey Carter <[email protected]>
1 parent ca2b2c6 commit 76c41da

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

stl/inc/generator

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,18 @@ namespace _Gen_detail {
110110
}
111111

112112
template <class _Alloc2, class... _Args>
113-
requires convertible_to<const _Alloc2&, _Proto_allocator>
114113
_NODISCARD_RAW_PTR_ALLOC static void* operator new(
115114
const size_t _Size, allocator_arg_t, const _Alloc2& _Al, const _Args&...) {
115+
static_assert(convertible_to<const _Alloc2&, _Proto_allocator>,
116+
"Allocator argument must be convertible to the allocator type (N5001 [coro.generator.promise]/18)");
116117
return _Allocate(static_cast<_Alloc>(static_cast<_Proto_allocator>(_Al)), _Size);
117118
}
118119

119120
template <class _This, class _Alloc2, class... _Args>
120-
requires convertible_to<const _Alloc2&, _Proto_allocator>
121121
_NODISCARD_RAW_PTR_ALLOC static void* operator new(
122122
const size_t _Size, const _This&, allocator_arg_t, const _Alloc2& _Al, const _Args&...) {
123+
static_assert(convertible_to<const _Alloc2&, _Proto_allocator>,
124+
"Allocator argument must be convertible to the allocator type (N5001 [coro.generator.promise]/18)");
123125
return _Allocate(static_cast<_Alloc>(static_cast<_Proto_allocator>(_Al)), _Size);
124126
}
125127

tests/std/tests/P2502R2_generator_promise/test.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,18 @@ void test_operator_new(typename Gen::promise_type& p, const Alloc2& alloc2 = {})
7878
}
7979

8080
// Test 'operator new(size_t, allocator_arg_t, const Alloc2&, const Args&...)'
81-
constexpr bool has_op_new2 = HasOperatorNew<Promise, size_t, allocator_arg_t, const Alloc2&, int, int>;
82-
static_assert(has_op_new2 == (same_as<Alloc, void> || convertible_to<const Alloc2&, Alloc>) );
83-
if constexpr (has_op_new2) {
81+
// This operator new is unconstrained.
82+
if constexpr (same_as<Alloc, void> || convertible_to<const Alloc2&, Alloc>) {
8483
const size_t size = __STDCPP_DEFAULT_NEW_ALIGNMENT__;
8584
void* const mem = p.operator new(size, allocator_arg, alloc2, 0, 0);
8685
assert(reinterpret_cast<uintptr_t>(mem) % __STDCPP_DEFAULT_NEW_ALIGNMENT__ == 0);
8786
p.operator delete(mem, size);
8887
}
8988

9089
// Test 'operator new(size_t, const This&, allocator_arg_t, const Alloc2&, const Args&...)'
90+
// This operator new is unconstrained.
9191
struct S {};
92-
constexpr bool has_op_new3 = HasOperatorNew<Promise, size_t, const S&, allocator_arg_t, const Alloc2&, int, int>;
93-
static_assert(has_op_new3 == (same_as<Alloc, void> || convertible_to<const Alloc2&, Alloc>) );
94-
if constexpr (has_op_new3) {
92+
if constexpr (same_as<Alloc, void> || convertible_to<const Alloc2&, Alloc>) {
9593
const size_t size = __STDCPP_DEFAULT_NEW_ALIGNMENT__;
9694
const S s;
9795
void* const mem = p.operator new(size, s, allocator_arg, alloc2, 0, 0);

0 commit comments

Comments
 (0)