|
145 | 145 | #define pg_nodiscard
|
146 | 146 | #endif
|
147 | 147 |
|
| 148 | +/* |
| 149 | + * pg_noreturn corresponds to the C11 noreturn/_Noreturn function specifier. |
| 150 | + * We can't use the standard name "noreturn" because some third-party code |
| 151 | + * uses __attribute__((noreturn)) in headers, which would get confused if |
| 152 | + * "noreturn" is defined to "_Noreturn", as is done by <stdnoreturn.h>. |
| 153 | + * |
| 154 | + * In a declaration, function specifiers go before the function name. The |
| 155 | + * common style is to put them before the return type. (The MSVC fallback has |
| 156 | + * the same requirement. The GCC fallback is more flexible.) |
| 157 | + */ |
| 158 | +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L |
| 159 | +#define pg_noreturn _Noreturn |
| 160 | +#elif defined(__GNUC__) || defined(__SUNPRO_C) |
| 161 | +#define pg_noreturn __attribute__((noreturn)) |
| 162 | +#elif defined(_MSC_VER) |
| 163 | +#define pg_noreturn __declspec(noreturn) |
| 164 | +#else |
| 165 | +#define pg_noreturn |
| 166 | +#endif |
| 167 | + |
148 | 168 | /*
|
149 | 169 | * This macro will disable address safety instrumentation for a function
|
150 | 170 | * when running with "-fsanitize=address". Think twice before using this!
|
|
213 | 233 | #define pg_attribute_printf(f,a)
|
214 | 234 | #endif
|
215 | 235 |
|
216 |
| -/* GCC and Sunpro support aligned, packed and noreturn */ |
| 236 | +/* GCC and Sunpro support aligned and packed */ |
217 | 237 | #if defined(__GNUC__) || defined(__SUNPRO_C)
|
218 | 238 | #define pg_attribute_aligned(a) __attribute__((aligned(a)))
|
219 |
| -#define pg_attribute_noreturn() __attribute__((noreturn)) |
220 | 239 | #define pg_attribute_packed() __attribute__((packed))
|
221 |
| -#define HAVE_PG_ATTRIBUTE_NORETURN 1 |
222 | 240 | #elif defined(_MSC_VER)
|
223 | 241 | /*
|
224 |
| - * MSVC supports aligned. noreturn is also possible but in MSVC it is |
225 |
| - * declared before the definition while pg_attribute_noreturn() macro |
226 |
| - * is currently used after the definition. |
| 242 | + * MSVC supports aligned. |
227 | 243 | *
|
228 | 244 | * Packing is also possible but only by wrapping the entire struct definition
|
229 | 245 | * which doesn't fit into our current macro declarations.
|
230 | 246 | */
|
231 | 247 | #define pg_attribute_aligned(a) __declspec(align(a))
|
232 |
| -#define pg_attribute_noreturn() |
233 | 248 | #else
|
234 | 249 | /*
|
235 | 250 | * NB: aligned and packed are not given default definitions because they
|
236 | 251 | * affect code functionality; they *must* be implemented by the compiler
|
237 | 252 | * if they are to be used.
|
238 | 253 | */
|
239 |
| -#define pg_attribute_noreturn() |
240 | 254 | #endif
|
241 | 255 |
|
242 | 256 | /*
|
@@ -858,8 +872,8 @@ typedef NameData *Name;
|
858 | 872 | * we should declare it as long as !FRONTEND.
|
859 | 873 | */
|
860 | 874 | #ifndef FRONTEND
|
861 |
| -extern void ExceptionalCondition(const char *conditionName, |
862 |
| - const char *fileName, int lineNumber) pg_attribute_noreturn(); |
| 875 | +pg_noreturn extern void ExceptionalCondition(const char *conditionName, |
| 876 | + const char *fileName, int lineNumber); |
863 | 877 | #endif
|
864 | 878 |
|
865 | 879 | /*
|
|
0 commit comments