ALib C++ Library
Library Version: 2312 R0
Documentation generated by doxygen
compilers.hpp
Go to the documentation of this file.
1 /** ************************************************************************************************
2  * \file
3  * This header file is part of the \aliblong. It does neither belong to a fileset, nor to a
4  * specific module of \alib, but is included in any \alibdist.
5  *
6  * \emoji :copyright: 2013-2023 A-Worx GmbH, Germany.
7  * Published under \ref mainpage_license "Boost Software License".
8  *
9  * \note
10  * This header is not shown in inclusion graphs of this documentation, as it is always
11  * included directly or indirectly.
12  **************************************************************************************************/
13 #ifndef HPP_ALIB_COMPILERS
14 #define HPP_ALIB_COMPILERS 1
15 
16 #if !defined(ALIB_DOX)
17  #define DOX_MARKER( marker )
18 #endif
19 
20 #if !defined(HPP_ALIB_MODULES) && !defined(ALIB_DOX)
21 # include "alib/lib/modules.hpp"
22 #endif
23 
24 // GCC Compiler detection
25 #if defined(__clang__)
26 #elif defined(__INTEL_COMPILER) //never tested
27 #elif defined(_MSC_VER)
28 #elif defined(__GNUC__)
29 # define ALIB_GCC 1
30 #endif
31 
32 
33 
34 // Debug or release compilation
35 #if !defined(ALIB_DEBUG)
36 # if !defined(NDEBUG) || defined(_DEBUG) || defined(DEBUG)
37 # define ALIB_DEBUG 1
38 # else
39 # define ALIB_DEBUG 0
40 # endif
41 #endif
42 
43 #if ALIB_DEBUG
44  #define ALIB_DBG(...) __VA_ARGS__
45  #define ALIB_REL(...)
46  #define ALIB_REL_DBG(releaseCode, ...) __VA_ARGS__
47 #else
48  #define ALIB_DBG(...)
49  #define ALIB_REL(...) __VA_ARGS__
50  #define ALIB_REL_DBG(releaseCode, ...) releaseCode
51 #endif
52 
53 // C++ standard
54 #if defined(ALIB_CPP11) || defined(ALIB_CPP14) || defined(ALIB_CPP17) || defined(ALIB_CPP20)
55 # error "Preprocessor symbols 'ALIB_CPP**' must not be given from outside."
56 #endif
57 
58 #if defined ( _MSC_VER ) && _MSC_VER < 1600 // VS 2010 == VC10 == _MSC_VER 1600
59 # error "ALib needs C++ 11. Compilation aborted"
60 #endif
61 #if defined(_MSVC_LANG)
62 # if _MSVC_LANG == 201103L
63 # define ALIB_CPPVER 11
64 # define ALIB_CPP11 1
65 # define ALIB_CPP14 0
66 # define ALIB_CPP17 0
67 # define ALIB_CPP20 0
68 # elif _MSVC_LANG == 201402L
69 # define ALIB_CPPVER 14
70 # define ALIB_CPP11 0
71 # define ALIB_CPP14 1
72 # define ALIB_CPP17 0
73 # define ALIB_CPP20 0
74 # elif _MSVC_LANG == 201703L
75 # define ALIB_CPPVER 17
76 # define ALIB_CPP11 0
77 # define ALIB_CPP14 0
78 # define ALIB_CPP17 1
79 # define ALIB_CPP20 0
80 # elif _MSVC_LANG >= 202002L
81 # define ALIB_CPPVER 20
82 # define ALIB_CPP11 0
83 # define ALIB_CPP14 0
84 # define ALIB_CPP17 0
85 # define ALIB_CPP20 1
86 # endif
87 #else
88 # if __cplusplus < 201103L
89 # error "ALib needs C++ 11. Compilation aborted"
90 # elif __cplusplus == 201103L
91 # define ALIB_CPPVER 11
92 # define ALIB_CPP11 1
93 # define ALIB_CPP14 0
94 # define ALIB_CPP17 0
95 # define ALIB_CPP20 0
96 # elif __cplusplus == 201402L
97 # define ALIB_CPPVER 14
98 # define ALIB_CPP11 0
99 # define ALIB_CPP14 1
100 # define ALIB_CPP17 0
101 # elif __cplusplus == 201703L
102 # define ALIB_CPPVER 17
103 # define ALIB_CPP11 0
104 # define ALIB_CPP14 0
105 # define ALIB_CPP17 1
106 # define ALIB_CPP20 0
107 # elif __cplusplus >= 202002L
108 # define ALIB_CPPVER 20
109 # define ALIB_CPP11 0
110 # define ALIB_CPP14 0
111 # define ALIB_CPP17 0
112 # define ALIB_CPP20 1
113 # endif
114 #endif
115 
116 #if ALIB_CPPVER >= 14
117 # define ALIB_CPP14_CONSTEXPR constexpr
118 # define ALIB_CPP14_REL_CONSTEXPR constexpr
119 #else
120 # define ALIB_CPP14_CONSTEXPR
121 # if ALIB_DEBUG
122 # define ALIB_CPP14_REL_CONSTEXPR
123 # else
124 # define ALIB_CPP14_REL_CONSTEXPR constexpr
125 # endif
126 #endif
127 
128 #if ALIB_CPPVER >= 17
129 # define ALIB_CPP17_CONSTEXPR constexpr
130 # define ALIB_CPP17_REL_CONSTEXPR constexpr
131 # define ALIB_CONSTEXPR17 constexpr
132 # define ALIB_NODISCARD [[nodiscard]]
133 #else
134 
135 # define ALIB_CPP17_CONSTEXPR
136 # if ALIB_DEBUG
137 # define ALIB_CPP17_REL_CONSTEXPR
138 # else
139 # define ALIB_CPP17_REL_CONSTEXPR constexpr
140 # endif
141 # define ALIB_CONSTEXPR17
142 # define ALIB_NODISCARD
143 #endif
144 
145 
146 
147 // Windows DLL Import/Export
148 #if defined( _MSC_VER ) && !defined( ALIB_API_NO_DLL )
149  #ifdef ALIB_API_IS_DLL
150  #define ALIB_API __declspec(dllexport)
151  #else
152  #define ALIB_API __declspec(dllimport)
153  #endif
154 #else
155  #define ALIB_API
156 #endif
157 
158 
159 // annotations
160 #if defined( _MSC_VER )
161 # define ALIB_FORCE_INLINE __forceinline
162 #else
163 # define ALIB_FORCE_INLINE __attribute__((always_inline)) inline
164 #endif
165 #define ALIB_NO_RETURN [[ noreturn ]]
166 
167 
168 // Warnings
169 #if defined(ALIB_GCC)
170 
171  #define ALIB_WARNINGS_UNINITIALIZED_OFF \
172  _Pragma("GCC diagnostic push") \
173  _Pragma("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") \
174 
175  #define ALIB_WARNINGS_ALLOW_NULL_POINTER_PASSING \
176  _Pragma("GCC diagnostic push") \
177  _Pragma("GCC diagnostic ignored \"-Wnonnull\"") \
178 
179  #define ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE \
180  _Pragma("GCC diagnostic push") \
181 
182  #define ALIB_WARNINGS_ALLOW_MACRO_REDEFINITION \
183  _Pragma("GCC diagnostic push") \
184 
185  #define ALIB_WARNINGS_ALLOW_UNSAFE_FUNCTION_OR_VARIABLE \
186  _Pragma("GCC diagnostic push") \
187 
188  #define ALIB_WARNINGS_MACRO_NOT_USED_OFF \
189  _Pragma("GCC diagnostic push") \
190 
191  #define ALIB_WARNINGS_RESERVED_MACRO_NAME_OFF \
192  _Pragma("GCC diagnostic push") \
193 
194  #define ALIB_WARNINGS_OVERLOAD_VIRTUAL_OFF \
195  _Pragma("GCC diagnostic push") \
196 
197  #define ALIB_WARNINGS_ALLOW_SPARSE_ENUM_SWITCH \
198  _Pragma("GCC diagnostic push") \
199 
200  #define ALIB_WARNINGS_ALLOW_BITWISE_SWITCH \
201  _Pragma("GCC diagnostic push") \
202  _Pragma("GCC diagnostic ignored \"-Wswitch\"") \
203 
204  #define ALIB_WARNINGS_ALLOW_SHIFT_COUNT_OVERFLOW \
205  _Pragma("GCC diagnostic push") \
206  _Pragma("GCC diagnostic ignored \"-Wshift-count-overflow\"") \
207 
208  #define ALIB_WARNINGS_IGNORE_UNUSED_PARAMETER \
209  _Pragma("GCC diagnostic push") \
210  _Pragma("GCC diagnostic ignored \"-Wunused-parameter\"") \
211 
212  #define ALIB_WARNINGS_IGNORE_UNUSED_MACRO \
213  _Pragma("GCC diagnostic push") \
214  _Pragma("GCC diagnostic ignored \"-Wunused-macros\"") \
215 
216  #define ALIB_WARNINGS_IGNORE_FUNCTION_TEMPLATE \
217  _Pragma("GCC diagnostic push") \
218 
219  #define ALIB_WARNINGS_IGNORE_NOTHING_RETURNED \
220  _Pragma("GCC diagnostic push") \
221  _Pragma("GCC diagnostic ignored \"-Wreturn-type\"") \
222 
223  #define ALIB_WARNINGS_IGNORE_IF_CONSTEXPR \
224  _Pragma("GCC diagnostic push") \
225 
226  #define ALIB_WARNINGS_IGNORE_INTEGRAL_CONSTANT_OVERFLOW \
227  _Pragma("GCC diagnostic push") \
228 
229  #define ALIB_WARNINGS_IGNORE_RESERVED_IDENTIFIER \
230  _Pragma("GCC diagnostic push") \
231 
232  #define ALIB_WARNINGS_IGNORE_DOCS \
233  _Pragma("GCC diagnostic push") \
234 
235  #define ALIB_WARNINGS_IGNORE_INTEGER_OVERFLOW \
236  _Pragma("GCC diagnostic push") \
237  _Pragma("GCC diagnostic ignored \"-Wshift-count-overflow\"") \
238 
239  #define ALIB_WARNINGS_RESTORE \
240  _Pragma("GCC diagnostic pop")
241 
242  #if __GNUC__ < 7
243  #define ALIB_FALLTHROUGH
244  #else
245  #define ALIB_FALLTHROUGH [[gnu::fallthrough]];
246  #endif
247 
248 #elif defined(__clang__)
249 
250  #define ALIB_WARNINGS_UNINITIALIZED_OFF \
251  _Pragma("clang diagnostic push") \
252  _Pragma("clang diagnostic ignored \"-Wuninitialized\"") \
253  _Pragma("clang diagnostic ignored \"-Wconditional-uninitialized\"") \
254 
255  #define ALIB_WARNINGS_ALLOW_NULL_POINTER_PASSING \
256  _Pragma("clang diagnostic push") \
257 
258  #define ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE \
259  _Pragma("clang diagnostic push") \
260  _Pragma("clang diagnostic ignored \"-Wunsafe-buffer-usage\"") \
261 
262  #define ALIB_WARNINGS_OVERLOAD_VIRTUAL_OFF \
263  _Pragma("clang diagnostic push") \
264  _Pragma("clang diagnostic ignored \"-Woverloaded-virtual\"") \
265 
266  #define ALIB_WARNINGS_ALLOW_MACRO_REDEFINITION \
267  _Pragma("clang diagnostic push") \
268  _Pragma("clang diagnostic ignored \"-Wmacro-redefined\"") \
269 
270  #define ALIB_WARNINGS_ALLOW_UNSAFE_FUNCTION_OR_VARIABLE \
271  _Pragma("clang diagnostic push") \
272  _Pragma("clang diagnostic ignored \"-Wunused-macros\"") \
273 
274 
275  #define ALIB_WARNINGS_MACRO_NOT_USED_OFF \
276  _Pragma("clang diagnostic push") \
277  _Pragma("clang diagnostic ignored \"-Wunused-macros\"") \
278 
279  #define ALIB_WARNINGS_RESERVED_MACRO_NAME_OFF \
280  _Pragma("clang diagnostic push") \
281  _Pragma("clang diagnostic ignored \"-Wreserved-macro-identifier\"") \
282 
283  #define ALIB_WARNINGS_ALLOW_SPARSE_ENUM_SWITCH \
284  _Pragma("clang diagnostic push") \
285  _Pragma("clang diagnostic ignored \"-Wswitch-enum\"") \
286 
287  #define ALIB_WARNINGS_ALLOW_BITWISE_SWITCH \
288  _Pragma("clang diagnostic push") \
289  _Pragma("clang diagnostic ignored \"-Wswitch\"") \
290  _Pragma("clang diagnostic ignored \"-Wcovered-switch-default\"") \
291 
292  #define ALIB_WARNINGS_ALLOW_SHIFT_COUNT_OVERFLOW \
293  _Pragma("clang diagnostic push") \
294  _Pragma("clang diagnostic ignored \"-Wshift-count-overflow\"") \
295 
296  #define ALIB_WARNINGS_IGNORE_UNUSED_PARAMETER \
297  _Pragma("clang diagnostic push") \
298  _Pragma("clang diagnostic ignored \"-Wunused-parameter\"") \
299 
300  #define ALIB_WARNINGS_IGNORE_UNUSED_MACRO \
301  _Pragma("clang diagnostic push") \
302  _Pragma("clang diagnostic ignored \"-Wunused-macros\"") \
303 
304  #define ALIB_WARNINGS_IGNORE_FUNCTION_TEMPLATE \
305  _Pragma("clang diagnostic push") \
306  _Pragma("clang diagnostic ignored \"-Wunused-template\"") \
307 
308  #define ALIB_WARNINGS_IGNORE_NOTHING_RETURNED \
309  _Pragma("clang diagnostic push") \
310  _Pragma("clang diagnostic ignored \"-Wreturn-type\"") \
311 
312  #define ALIB_WARNINGS_IGNORE_IF_CONSTEXPR \
313  _Pragma("clang diagnostic push") \
314 
315  #define ALIB_WARNINGS_IGNORE_INTEGRAL_CONSTANT_OVERFLOW \
316  _Pragma("clang diagnostic push") \
317 
318  #define ALIB_WARNINGS_IGNORE_DOCS \
319  _Pragma("clang diagnostic push") \
320  _Pragma("clang diagnostic ignored \"-Wdocumentation\"") \
321 
322  #define ALIB_WARNINGS_IGNORE_RESERVED_IDENTIFIER \
323  _Pragma("clang diagnostic push") \
324  _Pragma("clang diagnostic ignored \"-Wreserved-identifier\"") \
325 
326  #define ALIB_WARNINGS_IGNORE_INTEGER_OVERFLOW \
327  _Pragma("clang diagnostic push") \
328  _Pragma("clang diagnostic ignored \"-Winteger-overflow\"") \
329 
330 
331  #define ALIB_WARNINGS_RESTORE \
332  _Pragma("clang diagnostic pop") \
333 
334  #define ALIB_FALLTHROUGH [[clang::fallthrough]];
335 
336 
337 #elif defined(_MSC_VER)
338  #define ALIB_WARNINGS_UNINITIALIZED_OFF \
339  __pragma(warning( push )) \
340  __pragma(warning( disable : 4701 )) \
341 
342  #define ALIB_WARNINGS_ALLOW_NULL_POINTER_PASSING \
343  __pragma(warning( push )) \
344 
345  #define ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE \
346  __pragma(warning( push )) \
347 
348  #define ALIB_WARNINGS_MACRO_NOT_USED_OFF \
349  __pragma(warning( push )) \
350 
351  #define ALIB_WARNINGS_RESERVED_MACRO_NAME_OFF \
352  __pragma(warning( push )) \
353 
354  #define ALIB_WARNINGS_OVERLOAD_VIRTUAL_OFF \
355  __pragma(warning( push )) \
356 
357  #define ALIB_WARNINGS_ALLOW_SPARSE_ENUM_SWITCH \
358  __pragma(warning( push )) \
359 
360  #define ALIB_WARNINGS_ALLOW_SPARSE_ENUM_SWITCH \
361  __pragma(warning( push )) \
362 
363  #define ALIB_WARNINGS_ALLOW_MACRO_REDEFINITION \
364  __pragma(warning( push )) \
365  __pragma(warning( disable : 4005 )) \
366 
367  #define ALIB_WARNINGS_ALLOW_UNSAFE_FUNCTION_OR_VARIABLE \
368  __pragma(warning( push )) \
369  __pragma(warning( disable : 4996 )) \
370 
371  #define ALIB_WARNINGS_ALLOW_BITWISE_SWITCH \
372  __pragma(warning( push )) \
373 
374  #define ALIB_WARNINGS_ALLOW_SHIFT_COUNT_OVERFLOW \
375  __pragma(warning( push )) \
376 
377  #define ALIB_WARNINGS_IGNORE_UNUSED_PARAMETER \
378  __pragma(warning( push )) \
379 
380  #define ALIB_WARNINGS_IGNORE_UNUSED_MACRO \
381  __pragma(warning( push )) \
382 
383  #define ALIB_WARNINGS_IGNORE_FUNCTION_TEMPLATE \
384  __pragma(warning( push )) \
385 
386  #define ALIB_WARNINGS_IGNORE_NOTHING_RETURNED \
387  __pragma(warning( push )) \
388  __pragma(warning( disable : 4715 )) \
389 
390 #if ALIB_CPPVER < 17
391  #define ALIB_WARNINGS_IGNORE_IF_CONSTEXPR \
392  __pragma(warning( push )) \
393  __pragma(warning( disable : 4127 ))
394 #else
395  #define ALIB_WARNINGS_IGNORE_IF_CONSTEXPR \
396  __pragma(warning( push ))
397 #endif
398 
399  #define ALIB_WARNINGS_IGNORE_INTEGRAL_CONSTANT_OVERFLOW \
400  __pragma(warning( push )) \
401  __pragma(warning( disable : 4307 )) \
402  __pragma(warning( disable : 4293 )) \
403 
404  #define ALIB_WARNINGS_IGNORE_INTEGER_OVERFLOW \
405  __pragma(warning( push )) \
406  __pragma(warning( disable : 4293 )) \
407 
408  #define ALIB_WARNINGS_IGNORE_DOCS \
409  __pragma(warning( push )) \
410 
411  #define ALIB_WARNINGS_RESTORE \
412  __pragma(warning( pop )) \
413 
414  #define ALIB_FALLTHROUGH
415 
416 #else
417  #define ALIB_WARNINGS_RESTORE
418  #define ALIB_FALLTHROUGH
419 #endif
420 
421 
422 #endif // HPP_ALIB_COMPILERS
modules.hpp