• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef CONSCRYPT_SRC_MAIN_NATIVE_MACROS_H_
2 #define CONSCRYPT_SRC_MAIN_NATIVE_MACROS_H_
3 
4 // The FALLTHROUGH_INTENDED macro can be used to annotate implicit fall-through
5 // between switch labels:
6 //  switch (x) {
7 //    case 40:
8 //    case 41:
9 //      if (truth_is_out_there) {
10 //        ++x;
11 //        FALLTHROUGH_INTENDED;  // Use instead of/along with annotations in
12 //                               // comments.
13 //      } else {
14 //        return x;
15 //      }
16 //    case 42:
17 //      ...
18 //
19 //  As shown in the example above, the FALLTHROUGH_INTENDED macro should be
20 //  followed by a semicolon. It is designed to mimic control-flow statements
21 //  like 'break;', so it can be placed in most places where 'break;' can, but
22 //  only if there are no statements on the execution path between it and the
23 //  next switch label.
24 //
25 //  When compiled with clang in C++11 mode, the FALLTHROUGH_INTENDED macro is
26 //  expanded to [[clang::fallthrough]] attribute, which is analysed when
27 //  performing switch labels fall-through diagnostic ('-Wimplicit-fallthrough').
28 //  See clang documentation on language extensions for details:
29 //  http://clang.llvm.org/docs/LanguageExtensions.html#clang__fallthrough
30 //
31 //  When used with unsupported compilers, the FALLTHROUGH_INTENDED macro has no
32 //  effect on diagnostics.
33 //
34 //  In either case this macro has no effect on runtime behavior and performance
35 //  of code.
36 #if defined(__clang__) && __cplusplus >= 201103L && defined(__has_warning)
37 #if __has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough")
38 #define FALLTHROUGH_INTENDED [[clang::fallthrough]]  // NOLINT
39 #endif
40 #endif
41 
42 #ifndef FALLTHROUGH_INTENDED
43 #define FALLTHROUGH_INTENDED do { } while (0)
44 #endif
45 
46 #endif  // CONSCRYPT_SRC_MAIN_NATIVE_MACROS_H_
47