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

            Bug ID: 40997
           Summary: [coroutines] Clang should not consider use of co_await
                    within a move/copy-assignment operator as ill-formed
           Product: clang
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++2a
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected], [email protected]

>From https://reviews.llvm.org/D59076?id=189653#inline-522719

Clang currently raises an error if any special member function is compiled as a
coroutine. This includes constructors, destructors as well as copy/move
assignment operators.

However, N4775 only seems to have wording to disallow constructors/destructors
from being coroutines. With wording added to [class.ctor] and [class.dtor] but
no wording is added to [class.copy.assign] to disallow it from being a
coroutine.

See https://godbolt.org/z/cdhH3l

#include <experimental/coroutine>

using namespace std::experimental;

struct task {
    struct promise_type {
        suspend_never initial_suspend();
        suspend_never final_suspend();
        task get_return_object();
        void return_void();
        void unhandled_exception();
    };
};

struct X {
    task operator=(const X& other) {
        co_return; // ERROR: 'co_return' cannot be used in a copy assignment
operator
    }
    task operator=(X& other) {
        co_return; // ERROR: 'co_return' cannot be used in a copy assignment
operator
    }
    task operator=(X&& other) { 
        co_return; // ERROR: 'co_return' cannot be used in a move assignment
operator
    }
    task operator=(const X&& other) { 
        co_return; // ERROR: 'co_return' cannot be used in a move assignment
operator
    }
    task operator=(int x) {
        co_return; // OK
    }
};

All 5 of these should be accepted according to wording of N4775.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to