summaryrefslogtreecommitdiffstats
path: root/src/util.h
diff options
context:
space:
mode:
authorStefan Becker <chemobejk@gmail.com>2018-04-07 13:42:35 (GMT)
committerStefan Becker <chemobejk@gmail.com>2018-04-11 05:45:54 (GMT)
commit08ef815c7b55f28417b1a965eeab3640558d5f5a (patch)
tree6b71d8c69c973b6bbca9621c133623da79c7519b /src/util.h
parentca041d88f4d610332aa48c801342edfafb622ccb (diff)
downloadNinja-08ef815c7b55f28417b1a965eeab3640558d5f5a.zip
Ninja-08ef815c7b55f28417b1a965eeab3640558d5f5a.tar.gz
Ninja-08ef815c7b55f28417b1a965eeab3640558d5f5a.tar.bz2
Add NINJA_FALLTHROUGH macro
Borrow macro implementation from OpenSSL code. Add the macro after each fallthrough switch case to indicate our intention to the compiler. This silences GCC -Wimplicit-fallthrough warnings, which is implied by GCC 7.x -Wextra.
Diffstat (limited to 'src/util.h')
-rw-r--r--src/util.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/util.h b/src/util.h
index 4ee41a5..1b4227c 100644
--- a/src/util.h
+++ b/src/util.h
@@ -34,6 +34,20 @@ using namespace std;
/// Log a fatal message and exit.
NORETURN void Fatal(const char* msg, ...);
+// Have a generic fall-through for different versions of C/C++.
+#if defined(__cplusplus) && __cplusplus >= 201703L
+#define NINJA_FALLTHROUGH [[fallthrough]]
+#elif defined(__cplusplus) && __cplusplus >= 201103L && defined(__clang__)
+#define NINJA_FALLTHROUGH [[clang::fallthrough]]
+#elif defined(__cplusplus) && __cplusplus >= 201103L && defined(__GNUC__) && \
+ __GNUC__ >= 7
+#define NINJA_FALLTHROUGH [[gnu::fallthrough]]
+#elif defined(__GNUC__) && __GNUC__ >= 7 // gcc 7
+#define NINJA_FALLTHROUGH __attribute__ ((fallthrough))
+#else // C++11 on gcc 6, and all other cases
+#define NINJA_FALLTHROUGH
+#endif
+
/// Log a warning message.
void Warning(const char* msg, ...);