[PATCH] D26038: [coroutines] Sema: Allow co_return all by itself.

Gor Nishanov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 13 10:40:35 PST 2016


GorNishanov added a comment.

>> In https://reviews.llvm.org/D26038#613723, @EricWF wrote:
>> 
>>>



> Clang already treats functions with only co_return as coroutines, the diagnostic is a warning not an error.  Although IMHO Clang should emit a warning in this case. Obviously it's a false positive in your above example; but in general writing coroutines w/o `co_return` or `co_await` is a misuse of coroutines.

I am not sure about that. Consider these examples:

**Empty Generator**

  generator<int> g() { co_return; } // this is a generator representing an empty sequence.

Without co_return being legal, you would need to do something like;

  generator<int> g() { 
     if (0 != 0) co_yield 1;
   } 

Or **work in progress** async function:

  future<int> h() {
    // TODO: add more stuff
    co_return 42;
  }

would have to be:

  future<int> h() {
    // TODO: add more stuff
    co_await std::experimental::suspend_never{}; // to squash the warning
    co_return 42;
  }

I think coroutine by itself with just **co_return** is a reasonable approach. Besides, that is what the TS says :)


https://reviews.llvm.org/D26038





More information about the llvm-commits mailing list