Skip to content

Commit a36f4a2

Browse files
committed
Introduce LLVM_FALLTHROUGH, which expands to the C++17 attribute.
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
1 parent 7ad324b commit a36f4a2

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

llvm/include/llvm/Support/Compiler.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
# define __has_attribute(x) 0
3434
#endif
3535

36+
#ifndef __has_cpp_attribute
37+
# define __has_cpp_attribute(x) 0
38+
#endif
39+
3640
#ifndef __has_builtin
3741
# define __has_builtin(x) 0
3842
#endif
@@ -228,6 +232,15 @@
228232
#define LLVM_ATTRIBUTE_RETURNS_NOALIAS
229233
#endif
230234

235+
/// LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
236+
#if __has_cpp_attribute(fallthrough)
237+
#define LLVM_FALLTHROUGH [[fallthrough]]
238+
#elif __has_cpp_attribute(clang::fallthrough)
239+
#define LLVM_FALLTHROUGH [[clang::fallthrough]]
240+
#else
241+
#define LLVM_FALLTHROUGH
242+
#endif
243+
231244
/// LLVM_EXTENSION - Support compilers where we have a keyword to suppress
232245
/// pedantic diagnostics.
233246
#ifdef __GNUC__

0 commit comments

Comments
 (0)