Shaka Packager SDK
Loading...
Searching...
No Matches
compiler.h
1// Copyright 2023 Google LLC. 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_MACROS_COMPILER_H_
8#define PACKAGER_MACROS_COMPILER_H_
9
12#define UNUSED(x) (void)(x)
13
14// The FALLTHROUGH_INTENDED macro can be used to annotate implicit fall-through
15// between switch labels:
16// switch (x) {
17// case 40:
18// case 41:
19// if (truth_is_out_there) {
20// ++x;
21// FALLTHROUGH_INTENDED; // Use instead of/along with annotations in
22// // comments.
23// } else {
24// return x;
25// }
26// case 42:
27// ...
28//
29// As shown in the example above, the FALLTHROUGH_INTENDED macro should be
30// followed by a semicolon. It is designed to mimic control-flow statements
31// like 'break;', so it can be placed in most places where 'break;' can, but
32// only if there are no statements on the execution path between it and the
33// next switch label.
34//
35// When compiled with clang in C++11 mode, the FALLTHROUGH_INTENDED macro is
36// expanded to [[clang::fallthrough]] attribute, which is analysed when
37// performing switch labels fall-through diagnostic ('-Wimplicit-fallthrough').
38// See clang documentation on language extensions for details:
39// http://clang.llvm.org/docs/AttributeReference.html#fallthrough-clang-fallthrough
40//
41// When used with unsupported compilers, the FALLTHROUGH_INTENDED macro has no
42// effect on diagnostics.
43//
44// In either case this macro has no effect on runtime behavior and performance
45// of code.
46#if defined(__clang__) && __cplusplus >= 201103L && defined(__has_warning)
47#if __has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough")
48#define FALLTHROUGH_INTENDED [[clang::fallthrough]] // NOLINT
49#endif
50#endif
51
52#ifndef FALLTHROUGH_INTENDED
53#define FALLTHROUGH_INTENDED [[fallthrough]]
54#endif
55
56#endif // PACKAGER_MACROS_COMPILER_H_