Iros
 
Loading...
Searching...
No Matches
co_try.h
Go to the documentation of this file.
1#pragma once
2
4#include "di/util/move.h"
6
7#if __GNUC__ >= 13
8// NOTE: GCC 13 thinks that calling DI_TRY() on a di::Result<int&> produces a dangling reference, because the result
9// object gets destroyed before the reference is used. However, di::Result<int&> is essentially a pointer type, so this
10// is not a problem. Unfortunately, since this occurs in a macro, this warning cannot be suppressed only inside this
11// header file.
12#pragma GCC diagnostic ignored "-Wdangling-reference"
13#endif
14
15#define DI_CO_TRY(...) \
16 __extension__({ \
17 auto __result = (__VA_ARGS__); \
18 if (!__result) { \
19 co_return di::util::move(__result).__try_did_fail(); \
20 } \
21 ::di::util::move(__result).__try_did_succeed(); \
22 }).__try_move_out()
23
24#if !defined(DI_NO_GLOBALS) && !defined(DI_NO_GLOBAL_CO_TRY)
25#define CO_TRY DI_CO_TRY
26#endif