Repository navigation
Expand file tree
/
Copy pathattributes.hpp
More file actions
208 lines (188 loc) · 8.17 KB
/
Copy pathattributes.hpp
File metadata and controls
208 lines (188 loc) · 8.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
// _ _ _ _ _ _____
// /\ | | | | (_) | | | / ____|_ _
// / \ | |_| |_ _ __ _| |__ _ _| |_ ___ ___ | | _| |_ _| |_
// / /\ \| __| __| '__| | '_ \| | | | __/ _ \/ __| | | |_ _|_ _|
// / ____ \ |_| |_| | | | |_) | |_| | || __/\__ \ | |____|_| |_|
// /_/ \_\__|\__|_| |_|_.__/ \__,_|\__\___||___/ \_____|
//
// Licensed under the MIT License <http://opensource.org/licenses/MIT>.
// SPDX-License-Identifier: MIT
// Copyright (c) 2018 - 2026 Daniil Goncharov <neargye@gmail.com>.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#ifndef NEARGYE_NSTD_ATTRIBUTES_HPP
#define NEARGYE_NSTD_ATTRIBUTES_HPP
#if !defined(NEARGYE_ATTR_HAS_CPP_ATTRIBUTE)
# if defined(__has_cpp_attribute)
# define NEARGYE_ATTR_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
# else
# define NEARGYE_ATTR_HAS_CPP_ATTRIBUTE(x) 0
# endif
# define NEARGYE_ATTR_HAS_CPP_ATTRIBUTE_DEFINED
#endif
#if !defined(NEARGYE_ATTR_HAS_BUILTIN)
# if defined(__has_builtin)
# define NEARGYE_ATTR_HAS_BUILTIN(x) __has_builtin(x)
# else
# define NEARGYE_ATTR_HAS_BUILTIN(x) 0
# endif
# define NEARGYE_ATTR_HAS_BUILTIN_DEFINED
#endif
#if defined(_MSVC_LANG)
# define NEARGYE_ATTR_CPLUSPLUS _MSVC_LANG
#else
# define NEARGYE_ATTR_CPLUSPLUS __cplusplus
#endif
// ATTR_NORETURN indicates that the function does not return.
#if !defined(ATTR_NORETURN)
# if NEARGYE_ATTR_CPLUSPLUS >= 201103L && NEARGYE_ATTR_HAS_CPP_ATTRIBUTE(noreturn)
# define ATTR_NORETURN [[noreturn]]
# elif defined(__clang__) || defined(__GNUC__)
# define ATTR_NORETURN __attribute__((__noreturn__))
# elif defined(_MSC_VER)
# define ATTR_NORETURN __declspec(noreturn)
# else
# define ATTR_NORETURN
# endif
#endif
// ATTR_DEPRECATED indicates that the use of the name or entity declared with this attribute is allowed, but discouraged for some reason.
#if !defined(ATTR_DEPRECATED)
# if NEARGYE_ATTR_CPLUSPLUS >= 201402L && NEARGYE_ATTR_HAS_CPP_ATTRIBUTE(deprecated)
# define ATTR_DEPRECATED(MSG) [[deprecated(MSG)]]
# elif defined(__clang__) || defined(__GNUC__)
# define ATTR_DEPRECATED(MSG) __attribute__((__deprecated__(MSG)))
# elif defined(_MSC_VER)
# define ATTR_DEPRECATED(MSG) __declspec(deprecated(MSG))
# else
# define ATTR_DEPRECATED(MSG)
# endif
#endif
// ATTR_ALWAYS_INLINE strongly suggests that a function should be inlined.
#if !defined(ATTR_ALWAYS_INLINE)
# if defined(_MSC_VER)
# define ATTR_ALWAYS_INLINE __forceinline
# elif defined(__clang__) || defined(__GNUC__)
# define ATTR_ALWAYS_INLINE inline __attribute__((__always_inline__))
# else
# define ATTR_ALWAYS_INLINE inline
# endif
#endif
// ATTR_FALLTHROUGH indicates that the fall through from the previous case label is intentional and should not be diagnosed by a compiler that warns on fall-through.
#if !defined(ATTR_FALLTHROUGH)
# if NEARGYE_ATTR_CPLUSPLUS >= 201703L && NEARGYE_ATTR_HAS_CPP_ATTRIBUTE(fallthrough)
# define ATTR_FALLTHROUGH [[fallthrough]];
# elif defined(__clang__) && NEARGYE_ATTR_CPLUSPLUS >= 201103L
# define ATTR_FALLTHROUGH [[clang::fallthrough]];
# elif defined(__GNUC__) && __GNUC__ >= 7 && NEARGYE_ATTR_CPLUSPLUS >= 201103L
# define ATTR_FALLTHROUGH [[gnu::fallthrough]];
# else
# define ATTR_FALLTHROUGH /*fallthrough*/
# endif
#endif
// ATTR_ASSUME gives the optimizer an assumption about an expression. If the expression is false, behavior is undefined on supporting compilers.
#if !defined(ATTR_ASSUME)
# if NEARGYE_ATTR_CPLUSPLUS >= 202302L && NEARGYE_ATTR_HAS_CPP_ATTRIBUTE(assume)
# define ATTR_ASSUME(EXPR) [[assume(EXPR)]]
# elif defined(_MSC_VER)
# define ATTR_ASSUME(EXPR) __assume(EXPR)
# elif NEARGYE_ATTR_HAS_BUILTIN(__builtin_assume)
# define ATTR_ASSUME(EXPR) __builtin_assume(EXPR)
# else
# define ATTR_ASSUME(EXPR) static_cast<void>(0)
# endif
#endif
// ATTR_NODISCARD encourages the compiler to issue a warning if the return value is discarded.
#if !defined(ATTR_NODISCARD)
# if NEARGYE_ATTR_CPLUSPLUS >= 201703L && NEARGYE_ATTR_HAS_CPP_ATTRIBUTE(nodiscard)
# define ATTR_NODISCARD [[nodiscard]]
# elif defined(__clang__) || defined(__GNUC__)
# define ATTR_NODISCARD __attribute__((__warn_unused_result__))
# elif defined(_MSC_VER) && defined(_Check_return_)
# define ATTR_NODISCARD _Check_return_
# else
# define ATTR_NODISCARD
# endif
#endif
// ATTR_NODISCARD_MSG adds a diagnostic reason when supported.
#if !defined(ATTR_NODISCARD_MSG)
# if NEARGYE_ATTR_CPLUSPLUS >= 202002L && NEARGYE_ATTR_HAS_CPP_ATTRIBUTE(nodiscard) >= 201907L
# define ATTR_NODISCARD_MSG(MSG) [[nodiscard(MSG)]]
# else
# define ATTR_NODISCARD_MSG(MSG) ATTR_NODISCARD
# endif
#endif
// ATTR_MAYBE_UNUSED suppresses compiler warnings on unused entities, if any.
#if !defined(ATTR_MAYBE_UNUSED)
# if NEARGYE_ATTR_CPLUSPLUS >= 201703L && NEARGYE_ATTR_HAS_CPP_ATTRIBUTE(maybe_unused)
# define ATTR_MAYBE_UNUSED [[maybe_unused]]
# elif defined(__clang__) || defined(__GNUC__)
# define ATTR_MAYBE_UNUSED __attribute__((__unused__))
# elif defined(_MSC_VER)
# define ATTR_MAYBE_UNUSED __pragma(warning(suppress : 4100 4101 4189))
# else
# define ATTR_MAYBE_UNUSED
# endif
#endif
// ATTR_LIKELY hints that the expression is true.
#if !defined(ATTR_LIKELY)
# if defined(__clang__) || defined(__GNUC__)
# define ATTR_LIKELY(x) __builtin_expect(static_cast<bool>(x), 1)
# else
# define ATTR_LIKELY(x) (static_cast<bool>(x))
# endif
#endif
// ATTR_UNLIKELY hints that the expression is false.
#if !defined(ATTR_UNLIKELY)
# if defined(__clang__) || defined(__GNUC__)
# define ATTR_UNLIKELY(x) __builtin_expect(static_cast<bool>(x), 0)
# else
# define ATTR_UNLIKELY(x) (static_cast<bool>(x))
# endif
#endif
// ATTR_TRIVIAL_ABI requests Clang's trivial_abi calling convention for eligible class types.
#if !defined(ATTR_TRIVIAL_ABI)
# if defined(__clang__) && NEARGYE_ATTR_CPLUSPLUS >= 201103L && NEARGYE_ATTR_HAS_CPP_ATTRIBUTE(clang::trivial_abi)
# define ATTR_TRIVIAL_ABI [[clang::trivial_abi]]
# else
# define ATTR_TRIVIAL_ABI
# endif
#endif
// ATTR_NO_UNIQUE_ADDRESS allows member storage to overlap with other members or base classes.
// MSVC uses a vendor spelling for the ABI-affecting implementation.
// https://devblogs.microsoft.com/cppblog/msvc-cpp20-and-the-std-cpp20-switch/#msvc-extensions-and-abi
// https://github.com/microsoft/STL/issues/1364
#if !defined(ATTR_NO_UNIQUE_ADDRESS)
# if defined(_MSC_VER) && defined(_MSVC_LANG) && _MSVC_LANG >= 202002L && NEARGYE_ATTR_HAS_CPP_ATTRIBUTE(msvc::no_unique_address)
# define ATTR_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
# elif ((defined(_MSVC_LANG) && _MSVC_LANG >= 202002L) || __cplusplus >= 202002L) && NEARGYE_ATTR_HAS_CPP_ATTRIBUTE(no_unique_address) >= 201803L
# define ATTR_NO_UNIQUE_ADDRESS [[no_unique_address]]
# else
# define ATTR_NO_UNIQUE_ADDRESS
# endif
#endif
#if defined(NEARGYE_ATTR_HAS_CPP_ATTRIBUTE_DEFINED)
# undef NEARGYE_ATTR_HAS_CPP_ATTRIBUTE
# undef NEARGYE_ATTR_HAS_CPP_ATTRIBUTE_DEFINED
#endif
#if defined(NEARGYE_ATTR_HAS_BUILTIN_DEFINED)
# undef NEARGYE_ATTR_HAS_BUILTIN
# undef NEARGYE_ATTR_HAS_BUILTIN_DEFINED
#endif
#undef NEARGYE_ATTR_CPLUSPLUS
#endif // NEARGYE_NSTD_ATTRIBUTES_HPP