<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/60545>60545</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Coroutine codegen confused by top-level const in size parameter of custom delete for promise
</td>
</tr>
<tr>
<th>Labels</th>
<td>
c++20,
clang:frontend,
coroutines
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
CaseyCarter
</td>
</tr>
</table>
<pre>
Compiling this well-formed TU:
```c++
#include <coroutine>
#include <cstddef>
#ifdef WORKAROUND
#define CONST
#else
#define CONST const
#endif
struct generator {
struct promise_type {
generator get_return_object();
std::suspend_always initial_suspend();
std::suspend_always final_suspend() noexcept;
void return_void();
[[noreturn]] void unhandled_exception();
static void* operator new(std::size_t size);
static void operator delete(void* ptr, CONST std::size_t size); // Line 19
};
};
void f() { delete new generator::promise_type; } // Fine
generator g() { co_return; } // Line 24
```
with `clang -std=c++2b -stdlib=libc++` produces diagnostics (https://godbolt.org/z/7arWY6M98):
```
<source>:24:11: error: too few arguments to function call, expected 2, have 1
generator g() { co_return; } // Line 24
^
<source>:19:21: note: 'operator delete' declared here
static void operator delete(void* ptr, CONST std::size_t size); // Line 19
^
1 error generated.
```
Defining `WORKAROUND` (so `CONST` becomes empty instead of `const`) makes the problem go away. It would appear that the coroutine frame deallocation machinery in the compiler is confused by the presence of top-level `const` on `operator delete`'s second (`size_t`) parameter.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEVc2u2zYTfRp6M7iGTP3ZCy18rRj48LW5QJog6MqgyJHEliIFkrqO8_QFJdlyHWdRdFFDsMS_OTNnzgyZc7LRiAVJX0lartjgW2OLA3N4OTDr0a4qIy7FwXS9VFI34Fvp4IxKvdTGdijg8xcS70lUkmhPsmh6OKGv4ZlmaSw1V4NAIPGBG2sGLzWS-MPTdeeFwHpZve2pBdbw9e3T__ef3r58LG8LAmupEQ5vH3_7fJtE5f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