<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/64621>64621</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [Coroutines] Clang 17.0.0 rc2 cannot compile a final_suspend awaiter that is defined within final_suspend
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          Fulgen301
      </td>
    </tr>
</table>

<pre>
    When compiling a promise that [has its `final_suspend` awaiter defined within the function](https://gist.github.com/Fulgen301/f1856b3c940005040437afe07557814a), Clang 17 complains that it can't find the awaiter's member variable:

```
test.cpp:39:41: error: 'C4Task::Promise<void>::final_suspend()::Awaiter::await_suspend(const
 std::coroutine_handle<>)::Awaiter::promise' is not a member of class 'const Awaiter'
   39 |                     const auto waiter = promise.waiting.exchange(CompletedSentinel, std::memory_order_acq_rel);
 |                                         ^
test.cpp:33:20: note: in instantiation of member function
 'C4Task::Promise<void>::final_suspend()::Awaiter::await_suspend' requested here
   33 |             struct Awaiter : std::suspend_always
      | ^
test.cpp:42:25: error: 'C4Task::Promise<void>::final_suspend()::Awaiter::await_suspend(const
 std::coroutine_handle<>)::Awaiter::promise' is not a member of class 'const Awaiter'
   42 | promise.GetHandle().destroy();
```

If the awaiter struct is not defined within the function, the code compiles correctly.

The code in question compiled without errors in Clang 16 and also compiles on godbolt with Clang 18. I am running on Windows 11 x64 and have installed LLVM from the installer in the rc2 GitHub release.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkVcGO2zYQ_Rr6MohAkaJkHXzweuMkQAoUaNAcDUocS2wp0iGp3ezfF6Rk726y7a2nCIYsUsOZ996MZmQIerCIOyLuiLjfyDmOzu-OsxnQclpuOqeedl9HtNC76aKNtgNIuHg36YAQRxmBiLtRBtAxAKnpWVtpTmEOF7SK1BTko9QRPSg8a4sKHn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