]> granicus.if.org Git - clang/commitdiff
[coroutines] Diagnose when 'main' is declared as a coroutine.
authorEric Fiselier <eric@efcs.ca>
Fri, 30 Sep 2016 22:38:31 +0000 (22:38 +0000)
committerEric Fiselier <eric@efcs.ca>
Fri, 30 Sep 2016 22:38:31 +0000 (22:38 +0000)
Summary: The title says it all.

Reviewers: rsmith, GorNishanov

Subscribers: mehdi_amini, cfe-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@282973 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaCoroutine.cpp
test/SemaCXX/coroutines.cpp

index 00b9ca805ae3f2893714ded2da98bda0ddb69d18..58e8e00d85f759f896c8df7ffb1f91716aa8b02e 100644 (file)
@@ -8562,6 +8562,8 @@ def err_coroutine_ctor_dtor : Error<
   "'%1' cannot be used in a %select{constructor|destructor}0">;
 def err_coroutine_constexpr : Error<
   "'%0' cannot be used in a constexpr function">;
+def err_coroutine_main : Error<
+  "'main' cannot be a coroutine">;
 def err_coroutine_varargs : Error<
   "'%0' cannot be used in a varargs function">;
 def ext_coroutine_without_co_await_co_yield : ExtWarn<
index 514303608869e9ee6942e3f71e3faade7c0de0ca..461ca8eddcfec9ae7337285d62be0eb2868905cf 100644 (file)
@@ -127,6 +127,11 @@ checkCoroutineContext(Sema &S, SourceLocation Loc, StringRef Keyword) {
     S.Diag(Loc, diag::err_coroutine_constexpr) << Keyword;
   } else if (FD->isVariadic()) {
     S.Diag(Loc, diag::err_coroutine_varargs) << Keyword;
+  } else if (FD->isMain()) {
+    S.Diag(FD->getLocStart(), diag::err_coroutine_main);
+    S.Diag(Loc, diag::note_declared_coroutine_here)
+      << (Keyword == "co_await" ? 0 :
+          Keyword == "co_yield" ? 1 : 2);
   } else {
     auto *ScopeInfo = S.getCurFunction();
     assert(ScopeInfo && "missing function scope for function");
index d375e9eddb3770413371332b330b10727ebbc83b..92fdc7947442bdae225781d12db7e9f36af9457e 100644 (file)
@@ -283,3 +283,11 @@ struct bad_promise_5 {
 coro<bad_promise_5> bad_final_suspend() { // expected-error {{no member named 'await_ready' in 'not_awaitable'}}
   co_await a;
 }
+
+
+template<> struct std::coroutine_traits<int, int, const char**>
+{ using promise_type = promise; };
+
+int main(int, const char**) { // expected-error {{'main' cannot be a coroutine}}
+  co_await a; // expected-note {{function is a coroutine due to use of 'co_await' here}}
+}