https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114850
Bug ID: 114850
Summary: co_await a async function which result type is
std::unique_ptr<...> or shared_ptr in a initializer
list causes ICE
Product: gcc
Version: 13.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: jeremypewterschmidt at gmail dot com
Target Milestone: ---
I've noticed that there're some reports looks like the same, but I still
decided to report this to give you more information to help to resolve the
problem. But please make sure you read the snippet first.
Related reports:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99827
OS: Arch Linux x86_64 with kernel 6.8.7-zen1-1-zen
Although the OS is arch, but I have also tried this code in compiler explorer
with the same version, same options.
message dumped by g++ --version:
g++ (GCC) 13.2.1 20230801
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
command: g++ main.cpp --std=c++20 -freport-bug
Snippet caused the problem:
```c++
#include
#include
#include
//#include
template
struct Task {
struct Awaitable {
std::coroutine_handle<> coroutine;
T result;
bool await_ready() { return false; }
void await_suspend(std::coroutine_handle<> h) { coroutine = h; }
T await_resume() { return ::std::move(result); }
};
struct promise_type {
T value;
auto get_return_object() { return Task{
std::coroutine_handle::from_promise(*this) }; }
auto initial_suspend() { return std::suspend_never{}; }
auto final_suspend() noexcept { return std::suspend_always{}; }
void return_value(T val) { value = ::std::move(val); }
void unhandled_exception() {}
};
std::coroutine_handle coroutine;
Task(std::coroutine_handle coroutine) : coroutine(coroutine)
{}
~Task() noexcept {
if (coroutine)
coroutine.destroy();
}
T getResult() {
return coroutine.promise().value;
}
Awaitable operator co_await() {
return { coroutine, ::std::move(coroutine.promise().value) };
}
};
Task<::std::unique_ptr> uniqueGuy() {
co_return nullptr;
}
Task<::std::shared_ptr> sharedGuy() {
co_return nullptr;
}
//Task<::std::optional> optionalGuy() {
//co_return ::std::optional();
//}
Task intGuy()
{
co_return 0;
}
Task asyncFunction() {
//// OK
//::std::vector iVec{
//co_await intGuy(),
//co_await intGuy(),
//};
//
//// OK
//::std::vector optVec{
//co_await optionalGuy(),
//co_await optionalGuy(),
//};
//// ICE
//::std::vector uniqueVec{
//co_await uniqueGuy(),
//co_await uniqueGuy(),
//};
//
// ICE
::std::vector<::std::unique_ptr> uniqueVec2{
co_await uniqueGuy(),
co_await uniqueGuy(),
};
//// OK
//::std::vector<::std::unique_ptr> uniqueVec3;
//uniqueVec3.push_back(co_await uniqueGuy());
//uniqueVec3.push_back(co_await uniqueGuy());
//// ICE
//::std::vector sharedVec{
//co_await sharedGuy(),
//co_await sharedGuy(),
//};
co_return 0;
}
int main() {
return 0;
}
```
The ICE message:
src/main.cpp: In function ‘Task asyncFunction()’:
src/main.cpp:99:1: internal compiler error: in build_special_member_call, at
cp/call.cc:11093
99 | }
| ^
0x1ad33c8 internal_error(char const*, ...)
???:0
0x6b7b63 fancy_abort(char const*, int, char const*)
???:0
0x10dc463 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set >*,
tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set >*))
???:0
0x10dc463 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set >*,
tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set >*))
???:0
0x10dc463 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set >*,
tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set >*))
???:0
0x10dc463 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set >*,
tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set >*))
???:0
0x10dc583 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set >*,
tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set >*))
???:0
0x10dc463 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set >*,
tree_node* (*)(tree_node**,