Shaka Packager SDK
macros.h
1 // Copyright 2016 Google Inc. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file or at
5 // https://developers.google.com/open-source/licenses/bsd
6 
7 #ifndef PACKAGER_MEDIA_BASE_MACROS_H_
8 #define PACKAGER_MEDIA_BASE_MACROS_H_
9 
10 // The FALLTHROUGH_INTENDED macro can be used to annotate implicit fall-through
11 // between switch labels:
12 // switch (x) {
13 // case 40:
14 // case 41:
15 // if (truth_is_out_there) {
16 // ++x;
17 // FALLTHROUGH_INTENDED; // Use instead of/along with annotations in
18 // // comments.
19 // } else {
20 // return x;
21 // }
22 // case 42:
23 // ...
24 //
25 // As shown in the example above, the FALLTHROUGH_INTENDED macro should be
26 // followed by a semicolon. It is designed to mimic control-flow statements
27 // like 'break;', so it can be placed in most places where 'break;' can, but
28 // only if there are no statements on the execution path between it and the
29 // next switch label.
30 //
31 // When compiled with clang in C++11 mode, the FALLTHROUGH_INTENDED macro is
32 // expanded to [[clang::fallthrough]] attribute, which is analysed when
33 // performing switch labels fall-through diagnostic ('-Wimplicit-fallthrough').
34 // See clang documentation on language extensions for details:
35 // http://clang.llvm.org/docs/AttributeReference.html#fallthrough-clang-fallthrough
36 //
37 // When used with unsupported compilers, the FALLTHROUGH_INTENDED macro has no
38 // effect on diagnostics.
39 //
40 // In either case this macro has no effect on runtime behavior and performance
41 // of code.
42 #if defined(__clang__) && __cplusplus >= 201103L && defined(__has_warning)
43 #if __has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough")
44 #define FALLTHROUGH_INTENDED [[clang::fallthrough]] // NOLINT
45 #endif
46 #endif
47 
48 #ifndef FALLTHROUGH_INTENDED
49 #define FALLTHROUGH_INTENDED \
50  do { \
51  } while (0)
52 #endif
53 
54 #endif // PACKAGER_MEDIA_BASE_MACROS_H_