[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Parser / cxx20-coroutines.cpp
blob7207fb98587abd31c9d951c97dba35ed41a1fee7
1 // RUN: %clang_cc1 -std=c++20 %s -verify
3 template<typename T, typename U>
4 U f(T t) {
5 co_await t;
6 co_yield t;
8 1 + co_await t;
9 1 + co_yield t; // expected-error {{expected expression}}
11 auto x = co_await t;
12 auto y = co_yield t;
14 for co_await (int x : t) {} // expected-warning {{'for co_await' belongs to CoroutineTS instead of C++20, which is deprecated}}
15 for co_await (int x = 0; x != 10; ++x) {} // expected-error {{'co_await' modifier can only be applied to range-based for loop}}
17 if (t)
18 co_return t;
19 else
20 co_return {t};
23 struct Y {};
24 struct X { Y operator co_await(); };
25 struct Z {};
26 Y operator co_await(Z);
28 void f(X x, Z z) {
29 x.operator co_await();
30 operator co_await(z);
33 void operator co_await(); // expected-error {{must have at least one parameter}}
34 void operator co_await(X, Y, Z); // expected-error {{must be a unary operator}}
35 void operator co_await(int); // expected-error {{parameter of class or enumeration type}}