folly: add bser encode/decode for dynamic
[folly.git] / folly / CppAttributes.h
1 /*
2  * Copyright 2015 Facebook, Inc.
3  *
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
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 /**
18  * GCC compatible wrappers around clang attributes.
19  *
20  * @author Dominik Gabi
21  */
22
23 #ifndef FOLLY_BASE_ATTRIBUTES_H_
24 #define FOLLY_BASE_ATTRIBUTES_H_
25
26 #ifndef __has_cpp_attribute
27 #define FOLLY_HAS_CPP_ATTRIBUTE(x) 0
28 #else
29 #define FOLLY_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
30 #endif
31
32 #ifndef __has_extension
33 #define FOLLY_HAS_EXTENSION(x) 0
34 #else
35 #define FOLLY_HAS_EXTENSION(x) __has_extension(x)
36 #endif
37
38 /**
39  * Fallthrough to indicate that `break` was left out on purpose in a switch
40  * statement, e.g.
41  *
42  * switch (n) {
43  *   case 22:
44  *   case 33:  // no warning: no statements between case labels
45  *     f();
46  *   case 44:  // warning: unannotated fall-through
47  *     g();
48  *     FOLLY_FALLTHROUGH; // no warning: annotated fall-through
49  * }
50  */
51 #if FOLLY_HAS_CPP_ATTRIBUTE(clang::fallthrough)
52 #define FOLLY_FALLTHROUGH [[clang::fallthrough]]
53 #else
54 #define FOLLY_FALLTHROUGH
55 #endif
56
57 /**
58  * Nullable indicates that a return value or a parameter may be a `nullptr`,
59  * e.g.
60  *
61  * int* FOLLY_NULLABLE foo(int* a, int* FOLLY_NULLABLE b) {
62  *   if (*a > 0) {  // safe dereference
63  *     return nullptr;
64  *   }
65  *   if (*b < 0) {  // unsafe dereference
66  *     return *a;
67  *   }
68  *   if (b != nullptr && *b == 1) {  // safe checked dereference
69  *     return new int(1);
70  *   }
71  *   return nullptr;
72  * }
73  */
74 #if FOLLY_HAS_EXTENSION(nullability)
75 #define FOLLY_NULLABLE _Nullable
76 #else
77 #define FOLLY_NULLABLE
78 #endif
79
80 #endif /* FOLLY_BASE_ATTRIBUTES_H_ */