r312565 - [coroutines] Make sure auto return type of await_resume is properly handled

Gor Nishanov via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 5 12:31:52 PDT 2017


Author: gornishanov
Date: Tue Sep  5 12:31:52 2017
New Revision: 312565

URL: http://llvm.org/viewvc/llvm-project?rev=312565&view=rev
Log:
[coroutines] Make sure auto return type of await_resume is properly handled

Reviewers: rsmith, EricWF

Reviewed By: rsmith

Subscribers: javed.absar, cfe-commits

Differential Revision: https://reviews.llvm.org/D37454

Modified:
    cfe/trunk/lib/Sema/SemaCoroutine.cpp
    cfe/trunk/test/SemaCXX/coroutines.cpp

Modified: cfe/trunk/lib/Sema/SemaCoroutine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCoroutine.cpp?rev=312565&r1=312564&r2=312565&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCoroutine.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCoroutine.cpp Tue Sep  5 12:31:52 2017
@@ -438,14 +438,14 @@ static ReadySuspendResumeResult buildCoa
     //   - await-suspend is the expression e.await_suspend(h), which shall be
     //     a prvalue of type void or bool.
     QualType RetType = AwaitSuspend->getCallReturnType(S.Context);
+
     // Experimental support for coroutine_handle returning await_suspend.
     if (Expr *TailCallSuspend = maybeTailCall(S, RetType, AwaitSuspend, Loc))
       Calls.Results[ACT::ACT_Suspend] = TailCallSuspend;
     else {
       // non-class prvalues always have cv-unqualified types
-      QualType AdjRetType = RetType.getUnqualifiedType();
       if (RetType->isReferenceType() ||
-          (AdjRetType != S.Context.BoolTy && AdjRetType != S.Context.VoidTy)) {
+          (!RetType->isBooleanType() && !RetType->isVoidType())) {
         S.Diag(AwaitSuspend->getCalleeDecl()->getLocation(),
                diag::err_await_suspend_invalid_return_type)
             << RetType;

Modified: cfe/trunk/test/SemaCXX/coroutines.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/coroutines.cpp?rev=312565&r1=312564&r2=312565&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/coroutines.cpp (original)
+++ cfe/trunk/test/SemaCXX/coroutines.cpp Tue Sep  5 12:31:52 2017
@@ -66,6 +66,12 @@ struct suspend_never {
   void await_resume() {}
 };
 
+struct auto_await_suspend {
+  bool await_ready();
+  template <typename F> auto await_suspend(F) {}
+  void await_resume();
+};
+
 struct DummyVoidTag {};
 DummyVoidTag no_specialization() { // expected-error {{this function cannot be a coroutine: 'std::experimental::coroutine_traits<DummyVoidTag>' has no member named 'promise_type'}}
   co_await a;
@@ -159,6 +165,10 @@ void yield() {
   co_yield yield; // expected-error {{no member named 'await_ready' in 'not_awaitable'}}
 }
 
+void check_auto_await_suspend() {
+  co_await auto_await_suspend{}; // Should compile successfully.
+}
+
 void coreturn(int n) {
   co_await a;
   if (n == 0)




More information about the cfe-commits mailing list