https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125210

            Bug ID: 125210
           Summary: [coroutines] Change in coroutine frame destruction
                    behavior on exception since 14.3
           Product: gcc
           Version: 14.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rs2740 at gmail dot com
  Target Milestone: ---

#include <coroutine>
struct O {
    struct promise_type {
        std::suspend_never initial_suspend() const noexcept { return {}; }
        std::suspend_never final_suspend() const noexcept { return {}; }
        void unhandled_exception() { throw; }
        O get_return_object() noexcept { return {}; }
        void return_void() {}
    };

    bool await_ready() const noexcept { return false; }
    void await_suspend(std::coroutine_handle<promise_type> h) { h.destroy(); }
    decltype(auto) await_resume() const noexcept { return 1; }
};

O test() {
    throw 1;
    co_return;
}

int main() {
    try {
        test();
    }
    catch(...){}
}

-std=c++23 -O0 -fsanitize=address reports a leak on 14.3 but is OK on 14.2;
adding a print to promise_type's destructor confirms that it is not called in
14.3 or later but is called in 14.2. It's not clear what the correct behavior
is.

Reply via email to