xref: /aosp_15_r20/external/dynamic_depth/internal/base/macros.h (revision a62be0856e8e1158f43b03e41bbad10f4d005fde)
1 // This code is compiled directly on many platforms, including client
2 // platforms like Windows, Mac, and embedded systems.  Before making
3 // any changes here, make sure that you're not breaking any platforms.
4 //
5 
6 #ifndef DYNAMIC_DEPTH_INTERNAL_BASE_MACROS_H_  // NOLINT
7 #define DYNAMIC_DEPTH_INTERNAL_BASE_MACROS_H_  // NOLINT
8 
9 #include <stddef.h>  // For size_t
10 #include "base/port.h"
11 
12 // The FALLTHROUGH_INTENDED macro can be used to annotate implicit fall-through
13 // between switch labels:
14 //  switch (x) {
15 //    case 40:
16 //    case 41:
17 //      if (truth_is_out_there) {
18 //        ++x;
19 //        FALLTHROUGH_INTENDED;  // Use instead of/along with annotations in
20 //                               // comments.
21 //      } else {
22 //        return x;
23 //      }
24 //    case 42:
25 //      ...
26 //
27 //  As shown in the example above, the FALLTHROUGH_INTENDED macro should be
28 //  followed by a semicolon. It is designed to mimic control-flow statements
29 //  like 'break;', so it can be placed in most places where 'break;' can, but
30 //  only if there are no statements on the execution path between it and the
31 //  next switch label.
32 //
33 //  When compiled with clang in C++11 mode, the FALLTHROUGH_INTENDED macro is
34 //  expanded to [[clang::fallthrough]] attribute, which is analysed when
35 //  performing switch labels fall-through diagnostic ('-Wimplicit-fallthrough').
36 //  See clang documentation on language extensions for details:
37 //  http://clang.llvm.org/docs/AttributeReference.html#fallthrough-clang-fallthrough
38 //
39 //  When used with unsupported compilers, the FALLTHROUGH_INTENDED macro has no
40 //  effect on diagnostics.
41 //
42 //  In either case this macro has no effect on runtime behavior and performance
43 //  of code.
44 #if defined(__clang__) && defined(LANG_CXX11) && defined(__has_warning)
45 #if __has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough")
46 #define FALLTHROUGH_INTENDED [[clang::fallthrough]]  // NOLINT
47 #endif
48 #endif
49 
50 #ifndef FALLTHROUGH_INTENDED  // NOLINT
51 #define FALLTHROUGH_INTENDED \
52   do {                       \
53   } while (0)
54 #endif
55 
56 #endif // DYNAMIC_DEPTH_INTERNAL_BASE_MACROS_H_  // NOLINT
57