r328663 - [coroutines] Do not attempt to typo-correct when coroutine is looking for required members

Gor Nishanov via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 27 13:38:19 PDT 2018


Author: gornishanov
Date: Tue Mar 27 13:38:19 2018
New Revision: 328663

URL: http://llvm.org/viewvc/llvm-project?rev=328663&view=rev
Log:
[coroutines] Do not attempt to typo-correct when coroutine is looking for required members

When SemaCoroutine looks for await_resume, it means it. No need for helpful: "Did you mean await_ready?" messages.

Fixes PR33477 and a couple of FIXMEs in test/SemaCXX/coroutines.cpp

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=328663&r1=328662&r2=328663&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCoroutine.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCoroutine.cpp Tue Mar 27 13:38:19 2018
@@ -362,6 +362,15 @@ static ExprResult buildMemberCall(Sema &
   if (Result.isInvalid())
     return ExprError();
 
+  // We meant exactly what we asked for. No need for typo correction.
+  if (auto *TE = dyn_cast<TypoExpr>(Result.get())) {
+    S.clearDelayedTypo(TE);
+    S.Diag(Loc, diag::err_no_member)
+        << NameInfo.getName() << Base->getType()->getAsCXXRecordDecl()
+        << Base->getSourceRange();
+    return ExprError();
+  }
+
   return S.ActOnCallExpr(nullptr, Result.get(), Loc, Args, Loc, nullptr);
 }
 

Modified: cfe/trunk/test/SemaCXX/coroutines.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/coroutines.cpp?rev=328663&r1=328662&r2=328663&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/coroutines.cpp (original)
+++ cfe/trunk/test/SemaCXX/coroutines.cpp Tue Mar 27 13:38:19 2018
@@ -510,8 +510,7 @@ coro<bad_promise_1> missing_get_return_o
 
 struct bad_promise_2 {
   coro<bad_promise_2> get_return_object();
-  // FIXME: We shouldn't offer a typo-correction here!
-  suspend_always final_suspend(); // expected-note {{here}}
+  suspend_always final_suspend();
   void unhandled_exception();
   void return_void();
 };
@@ -522,8 +521,7 @@ coro<bad_promise_2> missing_initial_susp
 
 struct bad_promise_3 {
   coro<bad_promise_3> get_return_object();
-  // FIXME: We shouldn't offer a typo-correction here!
-  suspend_always initial_suspend(); // expected-note {{here}}
+  suspend_always initial_suspend();
   void unhandled_exception();
   void return_void();
 };
@@ -1378,3 +1376,22 @@ test_unused_warning() {
   co_await awaitable_unused_warn(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
   co_yield 42; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
 }
+
+struct missing_await_ready {
+  void await_suspend(std::experimental::coroutine_handle<>);
+  void await_resume();
+};
+struct missing_await_suspend {
+  bool await_ready();
+  void await_resume();
+};
+struct missing_await_resume {
+  bool await_ready();
+  void await_suspend(std::experimental::coroutine_handle<>);
+};
+
+void test_missing_awaitable_members() {
+  co_await missing_await_ready{}; // expected-error {{no member named 'await_ready' in 'missing_await_ready'}}
+  co_await missing_await_suspend{}; // expected-error {{no member named 'await_suspend' in 'missing_await_suspend'}}
+  co_await missing_await_resume{}; // expected-error {{no member named 'await_resume' in 'missing_await_resume'}}
+}




More information about the cfe-commits mailing list