summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2021-06-09 14:47:47 -0400
committerTavian Barnes <tavianator@tavianator.com>2021-06-09 14:55:45 -0400
commit41c148c4bf835fca788e6990cb8ea8651bb55927 (patch)
tree5be284c6143f63d4fa9c4a90a494bc41e505f7f3
parent6e080cda6978476b1c7ae8e08cd34f67e29aa147 (diff)
downloadbfs-41c148c4bf835fca788e6990cb8ea8651bb55927.tar.xz
util: Avoid warnings on older compilers with fallthrough
-rw-r--r--util.h12
1 files 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(<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)