proxygen
CppAttributes.h
Go to the documentation of this file.
1 /*
2  * Copyright 2015-present 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 
23 #pragma once
24 
25 #ifndef __has_attribute
26 #define FOLLY_HAS_ATTRIBUTE(x) 0
27 #else
28 #define FOLLY_HAS_ATTRIBUTE(x) __has_attribute(x)
29 #endif
30 
31 #ifndef __has_cpp_attribute
32 #define FOLLY_HAS_CPP_ATTRIBUTE(x) 0
33 #else
34 #define FOLLY_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
35 #endif
36 
37 #ifndef __has_extension
38 #define FOLLY_HAS_EXTENSION(x) 0
39 #else
40 #define FOLLY_HAS_EXTENSION(x) __has_extension(x)
41 #endif
42 
56 #if FOLLY_HAS_CPP_ATTRIBUTE(fallthrough)
57 #define FOLLY_FALLTHROUGH [[fallthrough]]
58 #elif FOLLY_HAS_CPP_ATTRIBUTE(clang::fallthrough)
59 #define FOLLY_FALLTHROUGH [[clang::fallthrough]]
60 #elif FOLLY_HAS_CPP_ATTRIBUTE(gnu::fallthrough)
61 #define FOLLY_FALLTHROUGH [[gnu::fallthrough]]
62 #else
63 #define FOLLY_FALLTHROUGH
64 #endif
65 
78 #if FOLLY_HAS_CPP_ATTRIBUTE(maybe_unused)
79 #define FOLLY_MAYBE_UNUSED [[maybe_unused]]
80 #elif FOLLY_HAS_ATTRIBUTE(__unused__) || __GNUC__
81 #define FOLLY_MAYBE_UNUSED __attribute__((__unused__))
82 #else
83 #define FOLLY_MAYBE_UNUSED
84 #endif
85 
103 #if FOLLY_HAS_EXTENSION(nullability)
104 #define FOLLY_NULLABLE _Nullable
105 #define FOLLY_NONNULL _Nonnull
106 #else
107 #define FOLLY_NULLABLE
108 #define FOLLY_NONNULL
109 #endif
110 
117 #if __GNUC__
118 #define FOLLY_COLD __attribute__((__cold__))
119 #else
120 #define FOLLY_COLD
121 #endif