Apache Mesos
attributes.hpp
Go to the documentation of this file.
1 // Licensed under the Apache License, Version 2.0 (the "License");
2 // you may not use this file except in compliance with the License.
3 // You may obtain a copy of the License at
4 //
5 // http://www.apache.org/licenses/LICENSE-2.0
6 //
7 // Unless required by applicable law or agreed to in writing, software
8 // distributed under the License is distributed on an "AS IS" BASIS,
9 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 // See the License for the specific language governing permissions and
11 // limitations under the License.
12 
13 #ifndef __STOUT_ATTRIBUTES_HPP__
14 #define __STOUT_ATTRIBUTES_HPP__
15 
16 #ifdef __has_cpp_attribute
17 # define STOUT_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
18 #else
19 # define STOUT_HAS_CPP_ATTRIBUTE(x) 0
20 #endif
21 
22 
23 // We unconditionally require compiler support for `noreturn`,
24 // both for legacy reasons and because the presence of this
25 // attribute might affect code generation.
26 #if STOUT_HAS_CPP_ATTRIBUTE(noreturn) > 0
27 # define STOUT_NORETURN [[noreturn]]
28 #elif defined(__WINDOWS__)
29 # define STOUT_NORETURN __declspec(noreturn)
30 #else
31 # define STOUT_NORETURN __attribute__((noreturn))
32 #endif
33 
34 // Non-namespaced version for backwards compatibility.
35 #define NORETURN STOUT_NORETURN
36 
37 
38 #if STOUT_HAS_CPP_ATTRIBUTE(nodiscard) > 0
39 # define STOUT_NODISCARD [[nodiscard]]
40 #else
41 # define STOUT_NODISCARD
42 #endif
43 
44 
45 // We need to special-case clang because some older versions of
46 // clang claim that they support `[[deprecated]]`, but will emit
47 // a warning that it should only be used after C++14 (failing the
48 // build if warnings are treated as errors).
49 //
50 // TODO(bevers): Add an optional argument to this macro, so users
51 // can specify a deprecation reason and a recommended alternative.
52 #if defined(__clang__) && __cplusplus >= 201402L
53 # define STOUT_DEPRECATED [[deprecated]]
54 #elif defined(__clang__)
55 # define STOUT_DEPRECATED __attribute__((deprecated))
56 #elif STOUT_HAS_CPP_ATTRIBUTE(deprecated) > 0
57 # define STOUT_DEPRECATED [[deprecated]]
58 #else
59 # define STOUT_DEPRECATED
60 #endif
61 
62 
63 #endif // __STOUT_ATTRIBUTES_HPP__