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

            Bug ID: 95813
           Summary: Making static member function a coroutine may cause
                    "defined but not used" warning for destroy(frame*)
                    function
           Product: gcc
           Version: 10.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gleb at scylladb dot com
  Target Milestone: ---

Compiling the code below with -Wall emits:

warn.cc:37:5: warning: ^Xגvoid
xxx::_ZN3xxx4funcEv.destroy(xxx::func()::_ZN3xxx4funcEv.frame*)^Yג defined but
not used [-Wunused-function]

and if foo() is uncommented the code compiles fine.

If should be OK to have the static member function in a header without getting
the warning.

#include <coroutine>
#include <functional>
#include <optional>
#include <cassert>

template <typename T>
class lazy {
    T _v = 0;
public:
    lazy() {}
    bool await_ready() {return true;}
    void await_suspend(auto x) noexcept {}
    T await_resume() { return _v; }
};

namespace std {

template <typename T, typename... Args>
struct coroutine_traits<lazy<T>, Args...> {
    struct promise_type {
        suspend_always initial_suspend() const { return {}; }
        suspend_always final_suspend() const { return {}; }
        void return_value(T val) {}
        lazy<T> get_return_object() {
            return lazy<T>();
        }
        void unhandled_exception() {
            std::terminate();
        }
    };
};
}

struct xxx {
    static lazy<int> func() {
        co_return 1;
    }
};

#if 0
lazy<int> foo() {
    co_return co_await xxx::func();
}
#endif

Reply via email to