macros: Define G_GNUC_FALLTHROUGH for more compilers

Some compilers have __GNUC__ defined as a value less than 6, but do
support implicit-fallthrough via __attribute__((fallthrough)). Define
G_GNUC_FALLTHROUGH for those that support __has_attribute.
This commit is contained in:
Timm Bäder
2020-02-28 08:59:23 +01:00
parent 369626e310
commit 5f38ae5ffc

View File

@@ -532,7 +532,7 @@
/**
* G_GNUC_FALLTHROUGH:
*
* Expands to the GNU C `fallthrough` statement attribute if the compiler is gcc.
* Expands to the GNU C `fallthrough` statement attribute if the compiler supports it.
* This allows declaring case statement to explicitly fall through in switch
* statements. To enable this feature, use `-Wimplicit-fallthrough` during
* compilation.
@@ -559,6 +559,8 @@
*/
#if __GNUC__ > 6
#define G_GNUC_FALLTHROUGH __attribute__((fallthrough))
#elif g_macro__has_attribute (fallthrough)
#define G_GNUC_FALLTHROUGH __attribute__((fallthrough))
#else
#define G_GNUC_FALLTHROUGH
#endif /* __GNUC__ */