expand support for noreturn declarations
Although gcc specifies support for declaring a function as noreturn after the function name and parameters, other compilers do so via an attribute at the start of the declaration. Add some macro support for the attribute-at-the-beginning method: o MS Visual Studio compiler o Upcoming C23 standard (untested at this point)
This commit is contained in:
@@ -393,6 +393,17 @@ typedef genericptr genericptr_t; /* (void *) or (char *) */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Give first priority to standard
|
||||
*/
|
||||
#ifndef ATTRNORETURN
|
||||
#if defined(__STDC_VERSION__) || defined(__cplusplus)
|
||||
#if (__STDC_VERSION__ > 202300L) || defined(__cplusplus)
|
||||
#define ATTRNORETURN [[noreturn]]
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Allow gcc2 to check parameters of printf-like calls with -Wformat;
|
||||
* append this to a prototype declaration (see pline() in extern.h).
|
||||
@@ -406,7 +417,11 @@ typedef genericptr genericptr_t; /* (void *) or (char *) */
|
||||
#endif
|
||||
#if __GNUC__ >= 3
|
||||
#define UNUSED __attribute__((unused))
|
||||
#ifndef ATTRNORETURN
|
||||
#ifndef NORETURN
|
||||
#define NORETURN __attribute__((noreturn))
|
||||
#endif
|
||||
#endif
|
||||
#if (!defined(__linux__) && !defined(MACOS)) || defined(GCC_URWARN)
|
||||
/* disable gcc's __attribute__((__warn_unused_result__)) since explicitly
|
||||
discarding the result by casting to (void) is not accepted as a 'use' */
|
||||
@@ -419,6 +434,12 @@ typedef genericptr genericptr_t; /* (void *) or (char *) */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#ifndef ATTRNORETURN
|
||||
#define ATTRNORETURN __declspec(noreturn)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef PRINTF_F
|
||||
#define PRINTF_F(f, v)
|
||||
#endif
|
||||
@@ -428,6 +449,9 @@ typedef genericptr genericptr_t; /* (void *) or (char *) */
|
||||
#ifndef UNUSED
|
||||
#define UNUSED
|
||||
#endif
|
||||
#ifndef ATTRNORETURN
|
||||
#define ATTRNORETURN
|
||||
#endif
|
||||
#ifndef NORETURN
|
||||
#define NORETURN
|
||||
#endif
|
||||
@@ -435,4 +459,5 @@ typedef genericptr genericptr_t; /* (void *) or (char *) */
|
||||
#define NONNULL
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* TRADSTDC_H */
|
||||
|
||||
Reference in New Issue
Block a user