[llvm-bugs] [Bug 48344] New: Coroutine promise types don't support destroying operator delete

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Nov 30 17:23:07 PST 2020


https://bugs.llvm.org/show_bug.cgi?id=48344

            Bug ID: 48344
           Summary: Coroutine promise types don't support destroying
                    operator delete
           Product: clang
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++2a
          Assignee: unassignedclangbugs at nondot.org
          Reporter: cygnus at michiru.ru
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

$ cat pdd.cpp

#if __has_include(<coroutine>)
#include <coroutine>
namespace stdcoro = std;
#else
#include <experimental/coroutine>
namespace stdcoro = std::experimental;
#endif

#include <cstdlib>
#include <new>

struct coroutine
{
    struct promise_type
    {
        coroutine get_return_object() noexcept
        {
            return {*this};
        }

        stdcoro::suspend_always initial_suspend() const noexcept
        {
            return {};
        }

        stdcoro::suspend_always final_suspend() const noexcept
        {
            return {};
        }

        void return_void() const noexcept {}

        void unhandled_exception() noexcept {}

        void* operator new(std::size_t n)
        {
            return std::malloc(n);
        }

        void operator delete(
            promise_type* p,std::destroying_delete_t,std::size_t)
        {
            std::free(p);
        }
    };

    stdcoro::coroutine_handle<promise_type> h_;

    coroutine(promise_type& p)
        : h_{decltype(h_)::from_promise(p)}
    {}

    ~coroutine()
    {
        h_.destroy();
    }
};

coroutine f()
{
    co_return;
}


$ clang++ -std=c++20 -fsyntax-only pdd.cpp

pdd.cpp:59:11: error: too few arguments to function call, expected 3, have 2
coroutine f()
          ^
pdd.cpp:40:14: note: 'operator delete' declared here
        void operator delete(
             ^
1 error generated.


Looking at the end of CoroutineStmtBuilder::makeNewAndDeleteExpr(), it seems
like support for destroying operator delete on promise types is not
implemented.

Neither gcc 10.2 nor MSVC 16.8.2 accept this code with similar error messages,
but it looks like it's impossible to implement a coroutine with statefull
Allocator support for promise that also has access to its allocator in its
implementation without support for this combination. I also can't find anything
that prohibits this in the C++ standard.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20201201/2a104b82/attachment-0001.html>


More information about the llvm-bugs mailing list