https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100772
Bug ID: 100772
Summary: Templated coroutine new function's arguments have
incorrect value categories/overload selection
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: davidledger at live dot com.au
Target Milestone: ---
Hello!
When using c++20 coroutines the overload selection for operator new is
incorrect.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The reference collapsing for reference arguments is disfunctional.
For this:
```CPP
Task Foo(auto && ... args) noexcept;
int v;
Foo(v, 2134);
```
With user provided new:
```CPP
void* operator new(std::size_t len, auto && ...args) noexcept;
```
No arguments are provided to the new function (ie. sizeof...(args) == 0). This
is demonstrated here:
https://godbolt.org/z/dd3PEbc74
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The arguments are not provided as lvalues:
For this:
```CPP
Task Foo(auto && ... args) noexcept;
int v;
Foo(v, 2134);
```
With this user provided operator new:
```CPP
void* operator new(std::size_t len, auto...args) noexcept;
```
The compiler selects this:
```CPP
void* operator new(std::size_t len, int &arg1, int &&arg2) noexcept;
```
Note, arg2 here is an rvalue, which is not as per the standard:
https://eel.is/c++draft/dcl.fct.def.coroutine#9.1
Specifically:
"...The lvalues p1…pn are the succeeding arguments."
There is an rvalue above. This is demonstrated here:
https://godbolt.org/z/Yx7T8ndn1