2 * Copyright 2016 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * GCC compatible wrappers around clang attributes.
20 * @author Dominik Gabi
23 #ifndef FOLLY_BASE_ATTRIBUTES_H_
24 #define FOLLY_BASE_ATTRIBUTES_H_
26 #ifndef __has_cpp_attribute
27 #define FOLLY_HAS_CPP_ATTRIBUTE(x) 0
29 #define FOLLY_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
32 #ifndef __has_extension
33 #define FOLLY_HAS_EXTENSION(x) 0
35 #define FOLLY_HAS_EXTENSION(x) __has_extension(x)
39 * Fallthrough to indicate that `break` was left out on purpose in a switch
44 * case 33: // no warning: no statements between case labels
46 * case 44: // warning: unannotated fall-through
48 * FOLLY_FALLTHROUGH; // no warning: annotated fall-through
51 #if FOLLY_HAS_CPP_ATTRIBUTE(clang::fallthrough)
52 #define FOLLY_FALLTHROUGH [[clang::fallthrough]]
54 #define FOLLY_FALLTHROUGH
58 * Nullable indicates that a return value or a parameter may be a `nullptr`,
61 * int* FOLLY_NULLABLE foo(int* a, int* FOLLY_NULLABLE b) {
62 * if (*a > 0) { // safe dereference
65 * if (*b < 0) { // unsafe dereference
68 * if (b != nullptr && *b == 1) { // safe checked dereference
74 #if FOLLY_HAS_EXTENSION(nullability)
75 #define FOLLY_NULLABLE _Nullable
77 #define FOLLY_NULLABLE
80 #endif /* FOLLY_BASE_ATTRIBUTES_H_ */