Introduce LLVM_FALLTHROUGH, which expands to the C++17 attribute.
authorJustin Bogner <mail@justinbogner.com>
Tue, 16 Aug 2016 23:24:13 +0000 (23:24 +0000)
committerJustin Bogner <mail@justinbogner.com>
Tue, 16 Aug 2016 23:24:13 +0000 (23:24 +0000)
This allows you to annotate switch case fallthrough in a better way
than a "// FALLTHROUGH" comment. Eventually it would be nice to turn
on -Wimplicit-fallthrough, if we can get the code base clean.

llvm-svn: 278868

llvm/include/llvm/Support/Compiler.h

index 516691f..6b00ff9 100644 (file)
 # define __has_attribute(x) 0
 #endif
 
+#ifndef __has_cpp_attribute
+# define __has_cpp_attribute(x) 0
+#endif
+
 #ifndef __has_builtin
 # define __has_builtin(x) 0
 #endif
 #define LLVM_ATTRIBUTE_RETURNS_NOALIAS
 #endif
 
+/// LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
+#if __has_cpp_attribute(fallthrough)
+#define LLVM_FALLTHROUGH [[fallthrough]]
+#elif __has_cpp_attribute(clang::fallthrough)
+#define LLVM_FALLTHROUGH [[clang::fallthrough]]
+#else
+#define LLVM_FALLTHROUGH
+#endif
+
 /// LLVM_EXTENSION - Support compilers where we have a keyword to suppress
 /// pedantic diagnostics.
 #ifdef __GNUC__