https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114728
Bug ID: 114728
Summary: Coroutine called in short-circuit fold expression
Product: gcc
Version: 13.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: yunus at ayar dot eu
Target Milestone: ---
Created attachment 57952
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57952&action=edit
Compressed version of a-test.ii
The following should print (and does with clang++ 17) only one `called` but it
prints it three times. Code (compiled with `g++ -std=c++20 test.cpp`):
```
#include <coroutine>
#include <iostream>
struct promise;
struct coroutine : std::coroutine_handle<promise> {
using promise_type = ::promise;
bool await_ready() { return true; }
void await_suspend(std::coroutine_handle<> h) {}
void await_resume() {}
};
struct promise {
coroutine get_return_object() { return { coroutine::from_promise(*this) }; }
std::suspend_never initial_suspend() noexcept { return {}; }
std::suspend_always final_suspend() noexcept { return {}; }
void return_void() {}
void unhandled_exception() {}
};
inline coroutine test(auto)
{
std::cout << "called\n";
co_return;
}
inline coroutine do_one(auto... v)
{
int i = 0;
((i++ == 1 && (co_await test(v), true)), ...);
}
int main() { do_one(1, 2, 3); }
```
I have also attached the compressed output of `g++ -save-temps`