diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2021-06-09 14:47:47 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2021-06-09 14:55:45 -0400 |
commit | 41c148c4bf835fca788e6990cb8ea8651bb55927 (patch) | |
tree | 5be284c6143f63d4fa9c4a90a494bc41e505f7f3 | |
parent | 6e080cda6978476b1c7ae8e08cd34f67e29aa147 (diff) | |
download | bfs-41c148c4bf835fca788e6990cb8ea8651bb55927.tar.xz |
util: Avoid warnings on older compilers with fallthrough
-rw-r--r-- | util.h | 12 |
1 files changed, 9 insertions, 3 deletions
@@ -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(<mntent.h>, __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) |