clang attribute wrappers
[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 /**
33  * Fallthrough to indicate that `break` was left out on purpose in a switch
34  * statement, e.g.
35  *
36  * switch (n) {
37  *   case 22:
38  *   case 33:  // no warning: no statements between case labels
39  *     f();
40  *   case 44:  // warning: unannotated fall-through
41  *     g();
42  *     FOLLY_FALLTHROUGH; // no warning: annotated fall-through
43  * }
44  */
45 #if FOLLY_HAS_CPP_ATTRIBUTE(clang::fallthrough)
46 #define FOLLY_FALLTHROUGH [[clang::fallthrough]]
47 #else
48 #define FOLLY_FALLTHROUGH
49 #endif
50
51 #endif /* FOLLY_BASE_ATTRIBUTES_H_ */