1 // RUN: %check_clang_tidy -std=c++20-or-later %s cppcoreguidelines-avoid-capturing-lambda-coroutines %t -- -- \
2 // RUN:   -isystem %S/../readability/Inputs/identifier-naming/system
3 
4 #include <coroutines.h>
5 
6 void Caught() {
7     int v;
8 
9     [&] () -> task { int y = v; co_return; };
10     // CHECK-MESSAGES: [[@LINE-1]]:5: warning: found capturing coroutine lambda [cppcoreguidelines-avoid-capturing-lambda-coroutines]
11     [=] () -> task { int y = v; co_return; };
12     // CHECK-MESSAGES: [[@LINE-1]]:5: warning: found capturing coroutine lambda [cppcoreguidelines-avoid-capturing-lambda-coroutines]
13     [v] () -> task { co_return; };
14     // CHECK-MESSAGES: [[@LINE-1]]:5: warning: found capturing coroutine lambda [cppcoreguidelines-avoid-capturing-lambda-coroutines]
15     [&v] () -> task { co_return; };
16     // CHECK-MESSAGES: [[@LINE-1]]:5: warning: found capturing coroutine lambda [cppcoreguidelines-avoid-capturing-lambda-coroutines]
17     [y=v] () -> task { co_return; };
18     // CHECK-MESSAGES: [[@LINE-1]]:5: warning: found capturing coroutine lambda [cppcoreguidelines-avoid-capturing-lambda-coroutines]
19     [y{v}] () -> task { co_return; };
20     // CHECK-MESSAGES: [[@LINE-1]]:5: warning: found capturing coroutine lambda [cppcoreguidelines-avoid-capturing-lambda-coroutines]
21 }
22 
23 struct S {
24     void m() {
25         [this] () -> task { co_return; };
26         // CHECK-MESSAGES: [[@LINE-1]]:9: warning: found capturing coroutine lambda [cppcoreguidelines-avoid-capturing-lambda-coroutines]
27     }
28 };
29 
30 void Safe() {
31     int v;
32     [] () -> task { co_return; };
33     [&] () -> task { co_return; };
34     [=] () -> task { co_return; };
35 }
36