xref: /llvm-project/clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape-coro.cpp (revision ff40c34881772e0641027327cd1791f4acacf6ff)
1 // RUN: %check_clang_tidy -std=c++20 %s bugprone-exception-escape %t -- \
2 // RUN:     -- -fexceptions
3 
4 namespace std {
5 
6 template <class Ret, typename... T> struct coroutine_traits {
7   using promise_type = typename Ret::promise_type;
8 };
9 
10 template <class Promise = void> struct coroutine_handle {
11   static coroutine_handle from_address(void *) noexcept;
12   static coroutine_handle from_promise(Promise &promise);
13   constexpr void *address() const noexcept;
14 };
15 
16 template <> struct coroutine_handle<void> {
17   template <class PromiseType>
18   coroutine_handle(coroutine_handle<PromiseType>) noexcept;
19   static coroutine_handle from_address(void *);
20   constexpr void *address() const noexcept;
21 };
22 
23 struct suspend_always {
await_readystd::suspend_always24   bool await_ready() noexcept { return false; }
await_suspendstd::suspend_always25   void await_suspend(coroutine_handle<>) noexcept {}
await_resumestd::suspend_always26   void await_resume() noexcept {}
27 };
28 
29 struct suspend_never {
await_readystd::suspend_never30   bool await_ready() noexcept { return true; }
await_suspendstd::suspend_never31   void await_suspend(coroutine_handle<>) noexcept {}
await_resumestd::suspend_never32   void await_resume() noexcept {}
33 };
34 
35 } // namespace std
36 
37 template <typename Task, typename T, bool ThrowInPromiseConstructor,
38           bool ThrowInInitialSuspend, bool ThrowInGetReturnObject,
39           bool ThrowInUnhandledException, bool RethrowInUnhandledException>
40 struct Promise;
41 
42 template <
43     typename T, bool ThrowInTaskConstructor = false,
44     bool ThrowInPromiseConstructor = false, bool ThrowInInitialSuspend = false,
45     bool ThrowInGetReturnObject = false, bool ThrowInUnhandledException = false,
46     bool RethrowInUnhandledException = false>
47 struct Task {
48   using promise_type =
49       Promise<Task, T, ThrowInPromiseConstructor, ThrowInInitialSuspend,
50               ThrowInGetReturnObject, ThrowInUnhandledException, RethrowInUnhandledException>;
51 
TaskTask52   explicit Task(promise_type &p) {
53     if constexpr (ThrowInTaskConstructor) {
54       throw 1;
55     }
56 
57     p.return_val = this;
58   }
59 
await_readyTask60   bool await_ready() { return true; }
61 
await_suspendTask62   void await_suspend(std::coroutine_handle<> h) {}
63 
await_resumeTask64   void await_resume() {}
65 
66   T value;
67 };
68 
69 template <bool ThrowInTaskConstructor, bool ThrowInPromiseConstructor,
70           bool ThrowInInitialSuspend, bool ThrowInGetReturnObject,
71           bool ThrowInUnhandledException, bool RethrowInUnhandledException>
72 struct Task<void, ThrowInTaskConstructor, ThrowInPromiseConstructor,
73             ThrowInInitialSuspend, ThrowInGetReturnObject,
74             ThrowInUnhandledException, RethrowInUnhandledException> {
75   using promise_type =
76       Promise<Task, void, ThrowInPromiseConstructor, ThrowInInitialSuspend,
77               ThrowInGetReturnObject, ThrowInUnhandledException, RethrowInUnhandledException>;
78 
TaskTask79   explicit Task(promise_type &p) {
80     if constexpr (ThrowInTaskConstructor) {
81       throw 1;
82     }
83 
84     p.return_val = this;
85   }
86 
await_readyTask87   bool await_ready() { return true; }
88 
await_suspendTask89   void await_suspend(std::coroutine_handle<> h) {}
90 
await_resumeTask91   void await_resume() {}
92 };
93 
94 template <typename Task, typename T, bool ThrowInPromiseConstructor,
95           bool ThrowInInitialSuspend, bool ThrowInGetReturnObject,
96           bool ThrowInUnhandledException, bool RethrowInUnhandledException>
97 struct Promise {
PromisePromise98   Promise() {
99     if constexpr (ThrowInPromiseConstructor) {
100       throw 1;
101     }
102   }
103 
get_return_objectPromise104   Task get_return_object() {
105     if constexpr (ThrowInGetReturnObject) {
106       throw 1;
107     }
108 
109     return Task{*this};
110   }
111 
initial_suspendPromise112   std::suspend_never initial_suspend() const {
113     if constexpr (ThrowInInitialSuspend) {
114       throw 1;
115     }
116 
117     return {};
118   }
119 
final_suspendPromise120   std::suspend_never final_suspend() const noexcept { return {}; }
121 
return_valuePromise122   template <typename U> void return_value(U &&val) {
123     return_val->value = static_cast<U &&>(val);
124   }
125 
yield_valuePromise126   template <typename U> std::suspend_never yield_value(U &&val) {
127     return_val->value = static_cast<U &&>(val);
128     return {};
129   }
130 
unhandled_exceptionPromise131   void unhandled_exception() {
132     if constexpr (ThrowInUnhandledException) {
133       throw 1;
134     } else if constexpr (RethrowInUnhandledException) {
135       throw;
136     }
137   }
138 
139   Task *return_val;
140 };
141 
142 template <typename Task, bool ThrowInPromiseConstructor,
143           bool ThrowInInitialSuspend, bool ThrowInGetReturnObject,
144           bool ThrowInUnhandledException, bool RethrowInUnhandledException>
145 struct Promise<Task, void, ThrowInPromiseConstructor, ThrowInInitialSuspend,
146                ThrowInGetReturnObject, ThrowInUnhandledException, RethrowInUnhandledException> {
PromisePromise147   Promise() {
148     if constexpr (ThrowInPromiseConstructor) {
149       throw 1;
150     }
151   }
152 
get_return_objectPromise153   Task get_return_object() {
154     if constexpr (ThrowInGetReturnObject) {
155       throw 1;
156     }
157 
158     return Task{*this};
159   }
160 
initial_suspendPromise161   std::suspend_never initial_suspend() const {
162     if constexpr (ThrowInInitialSuspend) {
163       throw 1;
164     }
165 
166     return {};
167   }
168 
final_suspendPromise169   std::suspend_never final_suspend() const noexcept { return {}; }
170 
return_voidPromise171   void return_void() {}
172 
unhandled_exceptionPromise173   void unhandled_exception() {
174     if constexpr (ThrowInUnhandledException) {
175       throw 1;
176     } else if constexpr (RethrowInUnhandledException) {
177       throw;
178     }
179   }
180 
181   Task *return_val;
182 };
183 
184 struct Evil {
~EvilEvil185   ~Evil() noexcept(false) {
186     throw 42;
187   }
188 };
189 
returnOne()190 Task<int> returnOne() { co_return 1; }
191 
192 namespace function {
193 
194 namespace coreturn {
195 
a_ShouldNotDiag(const int a,const int b)196 Task<int> a_ShouldNotDiag(const int a, const int b) {
197   if (b == 0)
198     throw b;
199 
200   co_return a / b;
201 }
202 
b_ShouldNotDiag(const int a,const int b)203 Task<int> b_ShouldNotDiag(const int a, const int b) noexcept {
204   if (b == 0)
205     throw b;
206 
207   co_return a / b;
208 }
209 
c_ShouldNotDiag(const int a,const int b)210 Task<int> c_ShouldNotDiag(const int a, const int b) {
211   if (b == 0)
212     throw Evil{};
213 
214   co_return a / b;
215 }
216 
c_ShouldDiag(const int a,const int b)217 Task<int> c_ShouldDiag(const int a, const int b) noexcept {
218   // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: an exception may be thrown in function 'c_ShouldDiag' which should not throw exceptions
219   if (b == 0)
220     throw Evil{};
221 
222   co_return a / b;
223 }
224 
d_ShouldNotDiag(const int a,const int b)225 Task<int, true> d_ShouldNotDiag(const int a, const int b) {
226   co_return a / b;
227 }
228 
d_ShouldDiag(const int a,const int b)229 Task<int, true> d_ShouldDiag(const int a, const int b) noexcept {
230   // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: an exception may be thrown in function 'd_ShouldDiag' which should not throw exceptions
231   co_return a / b;
232 }
233 
e_ShouldNotDiag(const int a,const int b)234 Task<int, false, true> e_ShouldNotDiag(const int a, const int b) {
235   co_return a / b;
236 }
237 
e_ShouldDiag(const int a,const int b)238 Task<int, false, true> e_ShouldDiag(const int a, const int b) noexcept {
239   // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: an exception may be thrown in function 'e_ShouldDiag' which should not throw exceptions
240   co_return a / b;
241 }
242 
f_ShouldNotDiag(const int a,const int b)243 Task<int, false, false, true> f_ShouldNotDiag(const int a, const int b) {
244   co_return a / b;
245 }
246 
f_ShouldDiag(const int a,const int b)247 Task<int, false, false, true> f_ShouldDiag(const int a, const int b) noexcept {
248   // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: an exception may be thrown in function 'f_ShouldDiag' which should not throw exceptions
249   co_return a / b;
250 }
251 
g_ShouldNotDiag(const int a,const int b)252 Task<int, false, false, false, true> g_ShouldNotDiag(const int a, const int b) {
253   co_return a / b;
254 }
255 
g_ShouldDiag(const int a,const int b)256 Task<int, false, false, false, true> g_ShouldDiag(const int a,
257                                                   const int b) noexcept {
258   // CHECK-MESSAGES: :[[@LINE-2]]:38: warning: an exception may be thrown in function 'g_ShouldDiag' which should not throw exceptions
259   co_return a / b;
260 }
261 
h_ShouldNotDiag(const int a,const int b)262 Task<int, false, false, false, false, true> h_ShouldNotDiag(const int a,
263                                                             const int b) {
264   co_return a / b;
265 }
266 
h_ShouldDiag(const int a,const int b)267 Task<int, false, false, false, false, true> h_ShouldDiag(const int a,
268                                                          const int b) noexcept {
269   // CHECK-MESSAGES: :[[@LINE-2]]:45: warning: an exception may be thrown in function 'h_ShouldDiag' which should not throw exceptions
270   co_return a / b;
271 }
272 
273 Task<int, false, false, false, false, false, true>
i_ShouldNotDiag(const int a,const int b)274 i_ShouldNotDiag(const int a, const int b) {
275   co_return a / b;
276 }
277 
278 Task<int, false, false, false, false, false, true>
i_ShouldNotDiagNoexcept(const int a,const int b)279 i_ShouldNotDiagNoexcept(const int a, const int b) noexcept {
280   co_return a / b;
281 }
282 
283 Task<int, false, false, false, false, false, true>
j_ShouldNotDiag(const int a,const int b)284 j_ShouldNotDiag(const int a, const int b) {
285   if (b == 0)
286     throw b;
287 
288   co_return a / b;
289 }
290 
291 Task<int, false, false, false, false, false, true>
j_ShouldDiag(const int a,const int b)292 j_ShouldDiag(const int a, const int b) noexcept {
293   // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: an exception may be thrown in function 'j_ShouldDiag' which should not throw exceptions
294   if (b == 0)
295     throw b;
296 
297   co_return a / b;
298 }
299 
300 } // namespace coreturn
301 
302 namespace coyield {
303 
a_ShouldNotDiag(const int a,const int b)304 Task<int> a_ShouldNotDiag(const int a, const int b) {
305   if (b == 0)
306     throw b;
307 
308   co_yield a / b;
309 }
310 
b_ShouldNotDiag(const int a,const int b)311 Task<int> b_ShouldNotDiag(const int a, const int b) noexcept {
312   if (b == 0)
313     throw b;
314 
315   co_yield a / b;
316 }
317 
c_ShouldNotDiag(const int a,const int b)318 Task<int> c_ShouldNotDiag(const int a, const int b) {
319   if (b == 0)
320     throw Evil{};
321 
322   co_yield a / b;
323 }
324 
c_ShouldDiag(const int a,const int b)325 Task<int> c_ShouldDiag(const int a, const int b) noexcept {
326   // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: an exception may be thrown in function 'c_ShouldDiag' which should not throw exceptions
327   if (b == 0)
328     throw Evil{};
329 
330   co_yield a / b;
331 }
332 
d_ShouldNotDiag(const int a,const int b)333 Task<int, true> d_ShouldNotDiag(const int a, const int b) {
334   co_yield a / b;
335 }
336 
d_ShouldDiag(const int a,const int b)337 Task<int, true> d_ShouldDiag(const int a, const int b) noexcept {
338   // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: an exception may be thrown in function 'd_ShouldDiag' which should not throw exceptions
339   co_yield a / b;
340 }
341 
e_ShouldNotDiag(const int a,const int b)342 Task<int, false, true> e_ShouldNotDiag(const int a, const int b) {
343   co_yield a / b;
344 }
345 
e_ShouldDiag(const int a,const int b)346 Task<int, false, true> e_ShouldDiag(const int a, const int b) noexcept {
347   // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: an exception may be thrown in function 'e_ShouldDiag' which should not throw exceptions
348   co_yield a / b;
349 }
350 
f_ShouldNotDiag(const int a,const int b)351 Task<int, false, false, true> f_ShouldNotDiag(const int a, const int b) {
352   co_yield a / b;
353 }
354 
f_ShouldDiag(const int a,const int b)355 Task<int, false, false, true> f_ShouldDiag(const int a, const int b) noexcept {
356   // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: an exception may be thrown in function 'f_ShouldDiag' which should not throw exceptions
357   co_yield a / b;
358 }
359 
g_ShouldNotDiag(const int a,const int b)360 Task<int, false, false, false, true> g_ShouldNotDiag(const int a, const int b) {
361   co_yield a / b;
362 }
363 
g_ShouldDiag(const int a,const int b)364 Task<int, false, false, false, true> g_ShouldDiag(const int a,
365                                                   const int b) noexcept {
366   // CHECK-MESSAGES: :[[@LINE-2]]:38: warning: an exception may be thrown in function 'g_ShouldDiag' which should not throw exceptions
367   co_yield a / b;
368 }
369 
h_ShouldNotDiag(const int a,const int b)370 Task<int, false, false, false, false, true> h_ShouldNotDiag(const int a,
371                                                             const int b) {
372   co_yield a / b;
373 }
374 
h_ShouldDiag(const int a,const int b)375 Task<int, false, false, false, false, true> h_ShouldDiag(const int a,
376                                                          const int b) noexcept {
377   // CHECK-MESSAGES: :[[@LINE-2]]:45: warning: an exception may be thrown in function 'h_ShouldDiag' which should not throw exceptions
378   co_yield a / b;
379 }
380 
381 Task<int, false, false, false, false, false, true>
i_ShouldNotDiag(const int a,const int b)382 i_ShouldNotDiag(const int a, const int b) {
383   co_yield a / b;
384 }
385 
386 Task<int, false, false, false, false, false, true>
i_ShouldNotDiagNoexcept(const int a,const int b)387 i_ShouldNotDiagNoexcept(const int a, const int b) noexcept {
388   co_yield a / b;
389 }
390 
391 Task<int, false, false, false, false, false, true>
j_ShouldNotDiag(const int a,const int b)392 j_ShouldNotDiag(const int a, const int b) {
393   if (b == 0)
394     throw b;
395 
396   co_yield a / b;
397 }
398 
399 Task<int, false, false, false, false, false, true>
j_ShouldDiag(const int a,const int b)400 j_ShouldDiag(const int a, const int b) noexcept {
401   // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: an exception may be thrown in function 'j_ShouldDiag' which should not throw exceptions
402   if (b == 0)
403     throw b;
404 
405   co_yield a / b;
406 }
407 
408 } // namespace coyield
409 
410 namespace coawait {
411 
a_ShouldNotDiag(const int a,const int b)412 Task<void> a_ShouldNotDiag(const int a, const int b) {
413   if (b == 0)
414     throw b;
415 
416   co_await returnOne();
417 }
418 
b_ShouldNotDiag(const int a,const int b)419 Task<void> b_ShouldNotDiag(const int a, const int b) noexcept {
420   if (b == 0)
421     throw b;
422 
423   co_await returnOne();
424 }
425 
c_ShouldNotDiag(const int a,const int b)426 Task<void> c_ShouldNotDiag(const int a, const int b) {
427   if (b == 0)
428     throw Evil{};
429 
430   co_await returnOne();
431 }
432 
c_ShouldDiag(const int a,const int b)433 Task<void> c_ShouldDiag(const int a, const int b) noexcept {
434   // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: an exception may be thrown in function 'c_ShouldDiag' which should not throw exceptions
435   if (b == 0)
436     throw Evil{};
437 
438   co_await returnOne();
439 }
440 
d_ShouldNotDiag(const int a,const int b)441 Task<void, true> d_ShouldNotDiag(const int a, const int b) {
442   co_await returnOne();
443 }
444 
d_ShouldDiag(const int a,const int b)445 Task<void, true> d_ShouldDiag(const int a, const int b) noexcept {
446   // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: an exception may be thrown in function 'd_ShouldDiag' which should not throw exceptions
447   co_await returnOne();
448 }
449 
e_ShouldNotDiag(const int a,const int b)450 Task<void, false, true> e_ShouldNotDiag(const int a, const int b) {
451   co_await returnOne();
452 }
453 
e_ShouldDiag(const int a,const int b)454 Task<void, false, true> e_ShouldDiag(const int a, const int b) noexcept {
455   // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: an exception may be thrown in function 'e_ShouldDiag' which should not throw exceptions
456   co_await returnOne();
457 }
458 
f_ShouldNotDiag(const int a,const int b)459 Task<void, false, false, true> f_ShouldNotDiag(const int a, const int b) {
460   co_await returnOne();
461 }
462 
f_ShouldDiag(const int a,const int b)463 Task<void, false, false, true> f_ShouldDiag(const int a, const int b) noexcept {
464   // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: an exception may be thrown in function 'f_ShouldDiag' which should not throw exceptions
465   co_await returnOne();
466 }
467 
g_ShouldNotDiag(const int a,const int b)468 Task<void, false, false, false, true> g_ShouldNotDiag(const int a,
469                                                       const int b) {
470   co_await returnOne();
471 }
472 
g_ShouldDiag(const int a,const int b)473 Task<void, false, false, false, true> g_ShouldDiag(const int a,
474                                                    const int b) noexcept {
475   // CHECK-MESSAGES: :[[@LINE-2]]:39: warning: an exception may be thrown in function 'g_ShouldDiag' which should not throw exceptions
476   co_await returnOne();
477 }
478 
h_ShouldNotDiag(const int a,const int b)479 Task<void, false, false, false, false, true> h_ShouldNotDiag(const int a,
480                                                              const int b) {
481   co_await returnOne();
482 }
483 
484 Task<void, false, false, false, false, true>
h_ShouldDiag(const int a,const int b)485 h_ShouldDiag(const int a, const int b) noexcept {
486   // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: an exception may be thrown in function 'h_ShouldDiag' which should not throw exceptions
487   co_await returnOne();
488 }
489 
490 Task<int, false, false, false, false, false, true>
i_ShouldNotDiag(const int a,const int b)491 i_ShouldNotDiag(const int a, const int b) {
492   co_await returnOne();
493 }
494 
495 Task<int, false, false, false, false, false, true>
i_ShouldNotDiagNoexcept(const int a,const int b)496 i_ShouldNotDiagNoexcept(const int a, const int b) noexcept {
497   co_await returnOne();
498 }
499 
500 Task<int, false, false, false, false, false, true>
j_ShouldNotDiag(const int a,const int b)501 j_ShouldNotDiag(const int a, const int b) {
502   co_await returnOne();
503   if (b == 0)
504     throw b;
505 }
506 
507 Task<int, false, false, false, false, false, true>
j_ShouldDiag(const int a,const int b)508 j_ShouldDiag(const int a, const int b) noexcept {
509   // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: an exception may be thrown in function 'j_ShouldDiag' which should not throw exceptions
510   co_await returnOne();
511   if (b == 0)
512     throw b;
513 }
514 
515 } // namespace coawait
516 
517 } // namespace function
518 
519 namespace lambda {
520 
521 namespace coreturn {
522 
__anonafba36150102(const int a, const int b) 523 const auto a_ShouldNotDiag = [](const int a, const int b) -> Task<int> {
524   if (b == 0)
525     throw b;
526 
527   co_return a / b;
528 };
529 
530 const auto b_ShouldNotDiag = [](const int a,
__anonafba36150202(const int a, const int b) 531                                 const int b) noexcept -> Task<int> {
532   if (b == 0)
533     throw b;
534 
535   co_return a / b;
536 };
537 
__anonafba36150302(const int a, const int b) 538 const auto c_ShouldNotDiag = [](const int a, const int b) -> Task<int> {
539   if (b == 0)
540     throw Evil{};
541 
542   co_return a / b;
543 };
544 
__anonafba36150402(const int a, const int b) 545 const auto c_ShouldDiag = [](const int a, const int b) noexcept -> Task<int> {
546   // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: an exception may be thrown in function 'operator()' which should not throw exceptions
547   if (b == 0)
548     throw Evil{};
549 
550   co_return a / b;
551 };
552 
__anonafba36150502(const int a, const int b) 553 const auto d_ShouldNotDiag = [](const int a, const int b) -> Task<int, true> {
554   co_return a / b;
555 };
556 
557 const auto d_ShouldDiag = [](const int a,
__anonafba36150602(const int a, const int b) 558                              const int b) noexcept -> Task<int, true> {
559   // CHECK-MESSAGES: :[[@LINE-2]]:27: warning: an exception may be thrown in function 'operator()' which should not throw exceptions
560   co_return a / b;
561 };
562 
563 const auto e_ShouldNotDiag = [](const int a,
__anonafba36150702(const int a, const int b) 564                                 const int b) -> Task<int, false, true> {
565   co_return a / b;
566 };
567 
568 const auto e_ShouldDiag = [](const int a,
__anonafba36150802(const int a, const int b) 569                              const int b) noexcept -> Task<int, false, true> {
570   // CHECK-MESSAGES: :[[@LINE-2]]:27: warning: an exception may be thrown in function 'operator()' which should not throw exceptions
571   co_return a / b;
572 };
573 
574 const auto f_ShouldNotDiag = [](const int a,
__anonafba36150902(const int a, const int b) 575                                 const int b) -> Task<int, false, false, true> {
576   co_return a / b;
577 };
578 
579 const auto f_ShouldDiag =
__anonafba36150a02(const int a, const int b) 580     [](const int a, const int b) noexcept -> Task<int, false, false, true> {
581   // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: an exception may be thrown in function 'operator()' which should not throw exceptions
582   co_return a / b;
583 };
584 
585 const auto g_ShouldNotDiag =
__anonafba36150b02(const int a, const int b) 586     [](const int a, const int b) -> Task<int, false, false, false, true> {
587   co_return a / b;
588 };
589 
590 const auto g_ShouldDiag =
591     [](const int a,
__anonafba36150c02(const int a, const int b) 592        const int b) noexcept -> Task<int, false, false, false, true> {
593   // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: an exception may be thrown in function 'operator()' which should not throw exceptions
594   co_return a / b;
595 };
596 
597 const auto h_ShouldNotDiag =
598     [](const int a,
__anonafba36150d02(const int a, const int b) 599        const int b) -> Task<int, false, false, false, false, true> {
600   co_return a / b;
601 };
602 
603 const auto h_ShouldDiag =
604     [](const int a,
__anonafba36150e02(const int a, const int b) 605        const int b) noexcept -> Task<int, false, false, false, false, true> {
606   // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: an exception may be thrown in function 'operator()' which should not throw exceptions
607   co_return a / b;
608 };
609 
610 const auto i_ShouldNotDiag =
611     [](const int a,
__anonafba36150f02(const int a, const int b) 612        const int b) -> Task<int, false, false, false, false, false, true> {
613   co_return a / b;
614 };
615 
616 const auto i_ShouldNotDiagNoexcept =
617     [](const int a,
__anonafba36151002(const int a, const int b) 618        const int b) noexcept -> Task<int, false, false, false, false, false, true> {
619   co_return a / b;
620 };
621 
622 const auto j_ShouldNotDiag =
623     [](const int a,
__anonafba36151102(const int a, const int b) 624        const int b) -> Task<int, false, false, false, false, false, true> {
625   if (b == 0)
626     throw b;
627 
628   co_return a / b;
629 };
630 
631 const auto j_ShouldDiag =
632     [](const int a,
__anonafba36151202(const int a, const int b) 633        const int b) noexcept -> Task<int, false, false, false, false, false, true> {
634   // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: an exception may be thrown in function 'operator()' which should not throw exceptions
635   if (b == 0)
636     throw b;
637 
638   co_return a / b;
639 };
640 
641 } // namespace coreturn
642 
643 namespace coyield {
644 
__anonafba36151302(const int a, const int b) 645 const auto a_ShouldNotDiag = [](const int a, const int b) -> Task<int> {
646   if (b == 0)
647     throw b;
648 
649   co_yield a / b;
650 };
651 
652 const auto b_ShouldNotDiag = [](const int a,
__anonafba36151402(const int a, const int b) 653                                 const int b) noexcept -> Task<int> {
654   if (b == 0)
655     throw b;
656 
657   co_yield a / b;
658 };
659 
__anonafba36151502(const int a, const int b) 660 const auto c_ShouldNotDiag = [](const int a, const int b) -> Task<int> {
661   if (b == 0)
662     throw Evil{};
663 
664   co_yield a / b;
665 };
666 
__anonafba36151602(const int a, const int b) 667 const auto c_ShouldDiag = [](const int a, const int b) noexcept -> Task<int> {
668   // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: an exception may be thrown in function 'operator()' which should not throw exceptions
669   if (b == 0)
670     throw Evil{};
671 
672   co_yield a / b;
673 };
674 
__anonafba36151702(const int a, const int b) 675 const auto d_ShouldNotDiag = [](const int a, const int b) -> Task<int, true> {
676   co_yield a / b;
677 };
678 
679 const auto d_ShouldDiag = [](const int a,
__anonafba36151802(const int a, const int b) 680                              const int b) noexcept -> Task<int, true> {
681   // CHECK-MESSAGES: :[[@LINE-2]]:27: warning: an exception may be thrown in function 'operator()' which should not throw exceptions
682   co_yield a / b;
683 };
684 
685 const auto e_ShouldNotDiag = [](const int a,
__anonafba36151902(const int a, const int b) 686                                 const int b) -> Task<int, false, true> {
687   co_yield a / b;
688 };
689 
690 const auto e_ShouldDiag = [](const int a,
__anonafba36151a02(const int a, const int b) 691                              const int b) noexcept -> Task<int, false, true> {
692   // CHECK-MESSAGES: :[[@LINE-2]]:27: warning: an exception may be thrown in function 'operator()' which should not throw exceptions
693   co_yield a / b;
694 };
695 
696 const auto f_ShouldNotDiag = [](const int a,
__anonafba36151b02(const int a, const int b) 697                                 const int b) -> Task<int, false, false, true> {
698   co_yield a / b;
699 };
700 
701 const auto f_ShouldDiag =
__anonafba36151c02(const int a, const int b) 702     [](const int a, const int b) noexcept -> Task<int, false, false, true> {
703   // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: an exception may be thrown in function 'operator()' which should not throw exceptions
704   co_yield a / b;
705 };
706 
707 const auto g_ShouldNotDiag =
__anonafba36151d02(const int a, const int b) 708     [](const int a, const int b) -> Task<int, false, false, false, true> {
709   co_yield a / b;
710 };
711 
712 const auto g_ShouldDiag =
713     [](const int a,
__anonafba36151e02(const int a, const int b) 714        const int b) noexcept -> Task<int, false, false, false, true> {
715   // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: an exception may be thrown in function 'operator()' which should not throw exceptions
716   co_yield a / b;
717 };
718 
719 const auto h_ShouldNotDiag =
720     [](const int a,
__anonafba36151f02(const int a, const int b) 721        const int b) -> Task<int, false, false, false, false, true> {
722   co_yield a / b;
723 };
724 
725 const auto h_ShouldDiag =
726     [](const int a,
__anonafba36152002(const int a, const int b) 727        const int b) noexcept -> Task<int, false, false, false, false, true> {
728   // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: an exception may be thrown in function 'operator()' which should not throw exceptions
729   co_yield a / b;
730 };
731 
732 const auto i_ShouldNotDiag =
733     [](const int a,
__anonafba36152102(const int a, const int b) 734        const int b) -> Task<int, false, false, false, false, false, true> {
735   co_yield a / b;
736 };
737 
738 const auto i_ShouldNotDiagNoexcept =
739     [](const int a,
__anonafba36152202(const int a, const int b) 740        const int b) noexcept -> Task<int, false, false, false, false, false, true> {
741   co_yield a / b;
742 };
743 
744 const auto j_ShouldNotDiag =
745     [](const int a,
__anonafba36152302(const int a, const int b) 746        const int b) -> Task<int, false, false, false, false, false, true> {
747   if (b == 0)
748     throw b;
749 
750   co_yield a / b;
751 };
752 
753 const auto j_ShouldDiag =
754     [](const int a,
__anonafba36152402(const int a, const int b) 755        const int b) noexcept -> Task<int, false, false, false, false, false, true> {
756   // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: an exception may be thrown in function 'operator()' which should not throw exceptions
757   if (b == 0)
758     throw b;
759 
760   co_yield a / b;
761 };
762 
763 } // namespace coyield
764 
765 namespace coawait {
766 
__anonafba36152502(const int a, const int b) 767 const auto a_ShouldNotDiag = [](const int a, const int b) -> Task<void> {
768   if (b == 0)
769     throw b;
770 
771   co_await returnOne();
772 };
773 
774 const auto b_ShouldNotDiag = [](const int a,
__anonafba36152602(const int a, const int b) 775                                 const int b) noexcept -> Task<void> {
776   if (b == 0)
777     throw b;
778 
779   co_await returnOne();
780 };
781 
__anonafba36152702(const int a, const int b) 782 const auto c_ShouldNotDiag = [](const int a, const int b) -> Task<void> {
783   if (b == 0)
784     throw Evil{};
785 
786   co_await returnOne();
787 };
788 
__anonafba36152802(const int a, const int b) 789 const auto c_ShouldDiag = [](const int a, const int b) noexcept -> Task<void> {
790   // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: an exception may be thrown in function 'operator()' which should not throw exceptions
791   if (b == 0)
792     throw Evil{};
793 
794   co_await returnOne();
795 };
796 
__anonafba36152902(const int a, const int b) 797 const auto d_ShouldNotDiag = [](const int a, const int b) -> Task<void, true> {
798   co_await returnOne();
799 };
800 
801 const auto d_ShouldDiag = [](const int a,
__anonafba36152a02(const int a, const int b) 802                              const int b) noexcept -> Task<void, true> {
803   // CHECK-MESSAGES: :[[@LINE-2]]:27: warning: an exception may be thrown in function 'operator()' which should not throw exceptions
804   co_await returnOne();
805 };
806 
807 const auto e_ShouldNotDiag = [](const int a,
__anonafba36152b02(const int a, const int b) 808                                 const int b) -> Task<void, false, true> {
809   co_await returnOne();
810 };
811 
812 const auto e_ShouldDiag = [](const int a,
__anonafba36152c02(const int a, const int b) 813                              const int b) noexcept -> Task<void, false, true> {
814   // CHECK-MESSAGES: :[[@LINE-2]]:27: warning: an exception may be thrown in function 'operator()' which should not throw exceptions
815   co_await returnOne();
816 };
817 
818 const auto f_ShouldNotDiag = [](const int a,
__anonafba36152d02(const int a, const int b) 819                                 const int b) -> Task<void, false, false, true> {
820   co_await returnOne();
821 };
822 
823 const auto f_ShouldDiag =
__anonafba36152e02(const int a, const int b) 824     [](const int a, const int b) noexcept -> Task<void, false, false, true> {
825   // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: an exception may be thrown in function 'operator()' which should not throw exceptions
826   co_await returnOne();
827 };
828 
829 const auto g_ShouldNotDiag =
__anonafba36152f02(const int a, const int b) 830     [](const int a, const int b) -> Task<void, false, false, false, true> {
831   co_await returnOne();
832 };
833 
834 const auto g_ShouldDiag =
835     [](const int a,
__anonafba36153002(const int a, const int b) 836        const int b) noexcept -> Task<void, false, false, false, true> {
837   // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: an exception may be thrown in function 'operator()' which should not throw exceptions
838   co_await returnOne();
839 };
840 
841 const auto h_ShouldNotDiag =
842     [](const int a,
__anonafba36153102(const int a, const int b) 843        const int b) -> Task<void, false, false, false, false, true> {
844   co_await returnOne();
845 };
846 
847 const auto h_ShouldDiag =
848     [](const int a,
__anonafba36153202(const int a, const int b) 849        const int b) noexcept -> Task<void, false, false, false, false, true> {
850   // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: an exception may be thrown in function 'operator()' which should not throw exceptions
851   co_await returnOne();
852 };
853 
854 const auto i_ShouldNotDiag =
855     [](const int a,
__anonafba36153302(const int a, const int b) 856        const int b) -> Task<int, false, false, false, false, false, true> {
857   co_await returnOne();
858 };
859 
860 const auto i_ShouldNotDiagNoexcept =
861     [](const int a,
__anonafba36153402(const int a, const int b) 862        const int b) noexcept -> Task<int, false, false, false, false, false, true> {
863   co_await returnOne();
864 };
865 
866 const auto j_ShouldNotDiag =
867     [](const int a,
__anonafba36153502(const int a, const int b) 868        const int b) -> Task<int, false, false, false, false, false, true> {
869   co_await returnOne();
870   if (b == 0)
871     throw b;
872 };
873 
874 const auto j_ShouldDiag =
875     [](const int a,
__anonafba36153602(const int a, const int b) 876        const int b) noexcept -> Task<int, false, false, false, false, false, true> {
877   // CHECK-MESSAGES: :[[@LINE-2]]:5: warning: an exception may be thrown in function 'operator()' which should not throw exceptions
878   co_await returnOne();
879   if (b == 0)
880     throw b;
881 };
882 
883 } // namespace coawait
884 
885 } // namespace lambda
886