https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102707
Bug ID: 102707
Summary: template coroutine generated code failed
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: netcan1996 at gmail dot com
Target Milestone: ---
code: https://godbolt.org/z/f591eaTja
```cpp
#include <coroutine>
#include <utility>
#include <exception>
#include <vector>
template<typename R>
struct task {
struct promise_type;
using coro_handle = std::coroutine_handle<promise_type>;
auto operator co_await() && noexcept {
return std::suspend_always{};
}
struct promise_type {
auto initial_suspend() noexcept { return std::suspend_always{}; }
auto final_suspend() noexcept {
return std::suspend_always {};
}
void unhandled_exception() { std::terminate(); }
task get_return_object() noexcept {
return {coro_handle::from_promise(*this)};
}
template<class U>
void return_value(U &&result) noexcept {
result_ = std::forward<U>(result);
}
R result_;
};
coro_handle handle_;
};
struct Dummy {};
template<size_t N>
task<Dummy> coro_depth_n(std::vector<int>& result) {
result.push_back(N);
if constexpr (N > 0) {
co_await coro_depth_n<N - 1>(result);
result.push_back(N * 10);
}
co_return Dummy{};
}
void test() {
std::vector<int> result;
auto t = coro_depth_n<4>(result);
}
```
compiled failed message:
<source>: In instantiation of 'task<Dummy> coro_depth_n(std::vector<int>&)
[with long unsigned int N = 4]':
<source>:49:29: required from here
<source>:44:5: internal compiler error: in tsubst_copy, at cp/pt.c:17314
44 | co_return Dummy{};
| ^~~~~~~~~
0x1ff4db9 internal_error(char const*, ...)
???:0
0x7d54cd fancy_abort(char const*, int, char const*)
???:0
0xa44627 instantiate_decl(tree_node*, bool, bool)
???:0
0xa8714b instantiate_pending_templates(int)
???:0
0x8ec779 c_parse_final_cleanups()
???:0
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
ASM generation compiler returned: 1
<source>: In instantiation of 'task<Dummy> coro_depth_n(std::vector<int>&)
[with long unsigned int N = 4]':
<source>:49:29: required from here
<source>:44:5: internal compiler error: in tsubst_copy, at cp/pt.c:17314
44 | co_return Dummy{};
| ^~~~~~~~~
0x1ff4db9 internal_error(char const*, ...)
???:0
0x7d54cd fancy_abort(char const*, int, char const*)
???:0
0xa44627 instantiate_decl(tree_node*, bool, bool)
???:0
0xa8714b instantiate_pending_templates(int)
???:0
0x8ec779 c_parse_final_cleanups()
???:0
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Execution build compiler returned: 1