Skip to content

Commit f7562f7

Browse files
committed
ignoring diagnostic on storing local pointer in class state
1 parent 06482fd commit f7562f7

File tree

1 file changed

+64
-44
lines changed

1 file changed

+64
-44
lines changed

inc/sq_coro.hpp

Lines changed: 64 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,23 @@ class coroState {
2727
~coroState() = default;
2828
void* label;
2929
};
30-
}
30+
} // namespace util
3131

3232
/**
3333
* @brief
3434
*
3535
* @param context context of the coroutine
3636
*
3737
*/
38-
#define CR_BEGIN(context) \
39-
util::coroState& localState = context; \
40-
do { \
41-
if (localState.label == nullptr) { \
42-
localState.label = &&CR_START; \
43-
} \
44-
goto* localState.label; \
38+
#define CR_BEGIN(context) \
39+
util::coroState& localState = context; \
40+
do { \
41+
if (localState.label == nullptr) { \
42+
_Pragma("GCC diagnostic ignored \"-Wdangling-pointer\""); \
43+
localState.label = &&CR_START; \
44+
_Pragma("GCC diagnostic pop"); \
45+
} \
46+
goto* localState.label; \
4547
CR_START:;
4648

4749
/**
@@ -50,20 +52,24 @@ class coroState {
5052
* @param retval return value to pass
5153
*
5254
*/
53-
#define CR_END(retval) \
54-
localState.label = &&CR_START; \
55-
return retval; \
56-
} \
55+
#define CR_END(retval) \
56+
_Pragma("GCC diagnostic ignored \"-Wdangling-pointer\""); \
57+
localState.label = &&CR_START; \
58+
_Pragma("GCC diagnostic pop"); \
59+
return retval; \
60+
} \
5761
while (0)
5862

5963
/**
6064
* @brief End of void function coroutines
6165
*
6266
*/
63-
#define CR_END_V() \
64-
localState.label = &&CR_START; \
65-
return; \
66-
} \
67+
#define CR_END_V() \
68+
_Pragma("GCC diagnostic ignored \"-Wdangling-pointer\""); \
69+
localState.label = &&CR_START; \
70+
_Pragma("GCC diagnostic pop"); \
71+
return; \
72+
} \
6773
while (0)
6874

6975
/**
@@ -72,22 +78,26 @@ class coroState {
7278
* @param retval return value to pass
7379
*
7480
*/
75-
#define CR_YIELD(retval) \
76-
do { \
77-
localState.label = &&CR_LABEL; \
78-
return (retval); \
79-
CR_LABEL:; \
81+
#define CR_YIELD(retval) \
82+
do { \
83+
_Pragma("GCC diagnostic ignored \"-Wdangling-pointer\""); \
84+
localState.label = &&CR_LABEL; \
85+
_Pragma("GCC diagnostic pop"); \
86+
return (retval); \
87+
CR_LABEL:; \
8088
} while (0)
8189

8290
/**
8391
* @brief Yield the coroutine
8492
*
8593
*/
86-
#define CR_YIELD_V() \
87-
do { \
88-
localState.label = &&CR_LABEL; \
89-
return; \
90-
CR_LABEL:; \
94+
#define CR_YIELD_V() \
95+
do { \
96+
_Pragma("GCC diagnostic ignored \"-Wdangling-pointer\""); \
97+
localState.label = &&CR_LABEL; \
98+
_Pragma("GCC diagnostic pop"); \
99+
return; \
100+
CR_LABEL:; \
91101
} while (0)
92102

93103
/**
@@ -97,11 +107,14 @@ class coroState {
97107
* @param cond condition to wait for
98108
*
99109
*/
100-
#define CR_WAIT(retval, cond) \
101-
do { \
102-
localState.label = &&CR_LABEL; \
103-
CR_LABEL:; \
104-
if (!(cond)) return retval; \
110+
#define CR_WAIT(retval, cond) \
111+
do { \
112+
_Pragma("GCC diagnostic ignored \"-Wdangling-pointer\""); \
113+
localState.label = &&CR_LABEL; \
114+
_Pragma("GCC diagnostic pop"); \
115+
CR_LABEL:; \
116+
if (!(cond)) \
117+
return retval; \
105118
} while (0)
106119

107120
/**
@@ -110,11 +123,14 @@ class coroState {
110123
* @param cond condition to wait for
111124
*
112125
*/
113-
#define CR_WAIT_V(cond) \
114-
do { \
115-
localState.label = &&CR_LABEL; \
116-
CR_LABEL:; \
117-
if (!(cond)) return; \
126+
#define CR_WAIT_V(cond) \
127+
do { \
128+
_Pragma("GCC diagnostic ignored \"-Wdangling-pointer\""); \
129+
localState.label = &&CR_LABEL; \
130+
_Pragma("GCC diagnostic pop"); \
131+
CR_LABEL:; \
132+
if (!(cond)) \
133+
return; \
118134
} while (0)
119135

120136
/**
@@ -123,20 +139,24 @@ class coroState {
123139
* @param retval return value to pass
124140
*
125141
*/
126-
#define CR_STOP(retval) \
127-
do { \
128-
localState.label = &&CR_START; \
129-
return (retval); \
142+
#define CR_STOP(retval) \
143+
do { \
144+
_Pragma("GCC diagnostic ignored \"-Wdangling-pointer\""); \
145+
localState.label = &&CR_START; \
146+
_Pragma("GCC diagnostic pop"); \
147+
return (retval); \
130148
} while (0)
131149

132150
/**
133151
* @brief Stop coroutine and go to beginning
134152
*
135153
*/
136-
#define CR_STOP_V(context) \
137-
do { \
138-
localState.label = &&CR_START; \
139-
return; \
154+
#define CR_STOP_V(context) \
155+
do { \
156+
_Pragma("GCC diagnostic ignored \"-Wdangling-pointer\""); \
157+
localState.label = &&CR_START; \
158+
_Pragma("GCC diagnostic pop"); \
159+
return; \
140160
} while (0)
141161

142162
#endif

0 commit comments

Comments
 (0)