From 41c148c4bf835fca788e6990cb8ea8651bb55927 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 9 Jun 2021 14:47:47 -0400 Subject: util: Avoid warnings on older compilers with fallthrough --- util.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/util.h b/util.h index 7b8b877..07580fc 100644 --- a/util.h +++ b/util.h @@ -48,6 +48,12 @@ # define BFS_HAS_C_ATTRIBUTE(attr) false #endif +#if __GNUC__ && defined(__has_attribute) +# define BFS_HAS_GNU_ATTRIBUTE(attr) __has_attribute(attr) +#else +# define BFS_HAS_GNU_ATTRIBUTE(attr) false +#endif + #ifndef BFS_HAS_MNTENT # define BFS_HAS_MNTENT BFS_HAS_INCLUDE(, __GLIBC__) #endif @@ -94,16 +100,16 @@ #if BFS_HAS_C_ATTRIBUTE(fallthrough) # define fallthrough [[fallthrough]] -#elif __GNUC__ +#elif BFS_HAS_GNU_ATTRIBUTE(fallthrough) # define fallthrough __attribute__((fallthrough)) #else -# define fallthrough +# define fallthrough ((void)0) #endif /** * Adds compiler warnings for bad printf()-style function calls, if supported. */ -#if __GNUC__ +#if BFS_HAS_GNU_ATTRIBUTE(format) # define BFS_FORMATTER(fmt, args) __attribute__((format(printf, fmt, args))) #else # define BFS_FORMATTER(fmt, args) -- cgit v1.2.3