[PATCH] libstdc++: Remove constraints on std::generator::promise_type::operator new

Arsen Arsenović arsen@aarsen.me
Wed Dec 11 14:59:10 GMT 2024


Jonathan Wakely <jwakely@redhat.com> writes:

>> +  for (auto _ : gen("const This& argument", std::allocator_arg , &mr))
>
> I have no idea what the promise_type::operator new overload that takes
> a const This& argument is for, but this invocation of gen uses it, so
> ... yay?

Member coroutines can call that overload:

  struct foo {
    std::generator<int, void, std::allocator<foo>>
    bar(std::allocator_arg_t, std::allocator<foo>) const&
    { co_yield 123; }
  };
  
  void f() {
      foo x;
      x.bar(std::allocator_arg, {});
  }

>> +    VERIFY(mr.number_of_active_allocations() == 1);
>> +
>> +  VERIFY(mr.number_of_active_allocations() == 0);
>> +}
>> diff --git a/libstdc++-v3/testsuite/24_iterators/range_generators/lwg3900.cc
>> b/libstdc++-v3/testsuite/24_iterators/range_generators/lwg3900.cc
>> new file mode 100644
>> index 00000000000..957879e8862
>> --- /dev/null
>> +++ b/libstdc++-v3/testsuite/24_iterators/range_generators/lwg3900.cc
>> @@ -0,0 +1,16 @@
>> +// { dg-do compile { target c++23 } }
>> +
>> +// LWG 3900. allocator_arg_t overloads of generator::promise_type::operator new
>> +// should not be constrained
>> +
>> +#include <generator>
>> +#include <memory_resource>
>> +
>> +std::pmr::generator<int>
>> +bar(std::allocator_arg_t, std::pmr::memory_resource& mr) // { dg-error "here" }
>> +{
>> +  co_yield 3;
>> +}
>> +
>> +// { dg-error "static assertion failed" "" { target *-*-* } 0 }
>> +// { dg-error "no matching function .*memory_resource&" "" { target *-*-* } 0 }
>> --
>> 2.47.1
>>

-- 
Arsen Arsenović
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 251 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/libstdc++/attachments/20241211/e4b6f8fa/attachment.sig>


More information about the Libstdc++ mailing list