<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/56989>56989</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang 14.0.6 on windows misdiagnoses valid code that clang 14.0.6 on linux compiles correctly
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
RoyAwesome
</td>
</tr>
</table>
<pre>
So, the following code gives me a very incorrect error on windows, however clang-14 on linux works. msvc compiles this code correctly
This code is cut down to just what is needed for the issue.
```cpp
#include <tuple>
#include <type_traits>
#include <coroutine>
template<typename AwaitableContainer>
class when_all_ready_awaitable;
template<typename... Tasks>
class when_all_ready_awaitable<std::tuple<Tasks...>>
{
public:
explicit when_all_ready_awaitable(Tasks&&... tasks)
: m_counter(sizeof...(Tasks))
, m_tasks(std::move(tasks)...)
{ }
auto operator co_await() &&
{
struct awaiter
{
awaiter(when_all_ready_awaitable& in_awaitable)
: m_awaitable(in_awaitable)
{ }
awaiter() = delete;
[[nodiscard]] bool await_ready() const noexcept
{
return true;
}
bool await_suspend(std::coroutine_handle<> in_coro) noexcept
{
return false;
}
std::tuple<Tasks...>&& await_resume() noexcept
{
return std::move(m_awaitable.m_tasks);
}
private:
when_all_ready_awaitable& m_awaitable;
};
return awaiter { *this };
}
private:
int m_counter;
std::tuple<Tasks...> m_tasks;
};
int main()
{
when_all_ready_awaitable<std::tuple<int, int>> foo(10, 10);
static_cast<when_all_ready_awaitable<std::tuple<int, int>>&&>(foo).operator co_await();
return 0;
}
```
Compiled on clang 14.0.6 on Windows:
```
clang++.exe -std=c++20 .\test.cpp
.\test.cpp:24:13: error: constructor for 'awaiter' must explicitly initialize the reference member 'm_awaitable'
awaiter(when_all_ready_awaitable& in_awaitable)
^
.\test.cpp:22:16: note: in instantiation of member function 'when_all_ready_awaitable<std::tuple<int, int>>::operator
co_await()::awaiter::awaiter' requested here
struct awaiter
^
.\test.cpp:44:39: note: declared here
when_all_ready_awaitable& m_awaitable;
^
.\test.cpp:41:34: error: 'when_all_ready_awaitable<std::tuple<int, int>>::operator
co_await()::awaiter::await_resume()::awaiter::m_awaitable' is not a member of class 'awaiter'
return std::move(m_awaitable.m_tasks);
^
.\test.cpp:22:16: note: in instantiation of member function 'when_all_ready_awaitable<std::tuple<int, int>>::operator
co_await()::awaiter::await_resume' requested here
struct awaiter
^
```
Where on Linux and msvc, this compiles correctly.
Obviously, I explicitly initialize the m_awaitable variable in there. This seems to be a bug for Clang on Windows.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzVV92P2zYM_2ucF-EMx86H_ZCHXNICAwYM2Ar0MZBtOlErS54kJ5f99aNkx7ET53rttRiWCP6SSP5IkRSZyvy8-kt64YaYA5BCci5PTOxJJnMge3YETUoglBxBnQkTmVQKMkNAKamIFAQX5_KkLYODPAEuIxmnYv80ndlpzkT9Qk5SfdU-IaU-Zsi5rBhHvubAdCOn5crPXrD1gnVz_dRN23ttCMoRxEjypdaGnA7U2AkBkEOOwJVTgGldA0rqM_IWQTOyqmq_hBGqwmvk7UUbU1ccvOjD6Ny5gp1RlBn9YAVil7VhosfBXQ2UFacGWiaCohnXJ2REUw4bKQxFGtURodG0Rq1A7CjnOwU0P-_oZb0XPQ80eiTB933yieqv-s18N9rkXrTG0Zph4-iRkWXRqbR8Jt2v-VTVKWeZJe1BstPwUuEEM4-FhnGDMVzgsJBN85pcmTg50ZqUu0zWwqChwlizf0AWFlnHILknQkcsdy3DuFOulEcr9yLIMelRWv285fZWFVqju8kKFDXoX5lsdEA-SEwa-GTAZIhFG1VjrDgi1GCI83axk9euDOPHtltgFPbfE3LP52q9vtFv6e5_95weGOYesAMSbUkOHMytvw44zp9xCJkznVGVe_MtDpJKyRtujcYtx0wKjHUh4SWDyozCG9degakVZgtVX7EMCbf3H3sgdK0xovK-C3WBvjtQkbtQwfiwu2FnLNofx1lQrr8B9H7q1cht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