https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98401
Michael Theall <pigman46 at gmail dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |pigman46 at gmail dot com --- Comment #5 from Michael Theall <pigman46 at gmail dot com> --- This is also happening for me. In my case i have a promise_type defined by coroutine_traits. This promise_type contains only a shared_ptr, which is constructed via make_shared on default and move constructors, and the copy constructor is deleted. a promise_type x is default-constructed and then immediately another promise_type y is move-constructed from x but with the wrong reference. I'll call it x'. promise_type contains a shared_ptr which has the same reference in both x and x' although x' is never constructed, and the shared_ptr has a refcount of 1. So now we have x with its original shared_ptr 'a'. We have x' with some unspecified shared_ptr 'b' (it was swapped or destroyed when moved to y). We have y also with shared_ptr 'a'. The refcount of 'a' at this point is still 1. Then, by the time my coroutine returns, all of x, x', and y are destructed, which means shared_ptr 'a' is destructed too many times. shared_ptr 'b' is fine. If I assign the awaitable to a local variable and then co_await that instead, the problem does not occur. In no cases does the problem occur with clang. Same behavior on GCC 11.2.1 x86_64 with -std=c++20 and GCC 11.1.0 aarch64 with -std=gnu++20. The problem occurs regardless of optimization level and whether LTO is enabled, if that makes any difference.