Is this UB or a bug in GCC or Clang
Hi, I have run into an issue with capturing coroutines in c++, and I would like to know if it is GCC or Clang that is wrong here. I have a reproducible example(https://godbolt.org/z/9Mh36ro3x), I would expect the code to print "hello" which Clang correctly does, but GCC prints an empty string and I have also seen it print "garbage"(https://godbolt.org/z/a77YsM1fT), and segfault the program. Here is the part of the program that triggers this I think:
auto execute() const {
return & -> boost::asio::awaitable<int> {
mfunction();
coreturn 0;
}();
}
I would expect that the captured "this" pointer to be valid until the first yield point since we immediately execute it, and thus the call to m_function should be just fine, which it is in Clang, but this fails catastrophically in GCC.
Which compiler is right, or is it just undefined behavior?
https://redd.it/1ojy2l9
@r_cpp
Post #24138
19