1/****************************************************************************
2**
3** Copyright (C) 2020 The Qt Company Ltd.
4** Copyright (C) 2016 Intel Corporation.
5** Contact: https://www.qt.io/licensing/
6**
7** This file is part of the QtCore module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial License Usage
11** Licensees holding valid commercial Qt licenses may use this file in
12** accordance with the commercial license agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and The Qt Company. For licensing terms
15** and conditions see https://www.qt.io/terms-conditions. For further
16** information use the contact form at https://www.qt.io/contact-us.
17**
18** GNU Lesser General Public License Usage
19** Alternatively, this file may be used under the terms of the GNU Lesser
20** General Public License version 3 as published by the Free Software
21** Foundation and appearing in the file LICENSE.LGPL3 included in the
22** packaging of this file. Please review the following information to
23** ensure the GNU Lesser General Public License version 3 requirements
24** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
25**
26** GNU General Public License Usage
27** Alternatively, this file may be used under the terms of the GNU
28** General Public License version 2.0 or (at your option) the GNU General
29** Public license version 3 or any later version approved by the KDE Free
30** Qt Foundation. The licenses are as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
32** included in the packaging of this file. Please review the following
33** information to ensure the GNU General Public License requirements will
34** be met: https://www.gnu.org/licenses/gpl-2.0.html and
35** https://www.gnu.org/licenses/gpl-3.0.html.
36**
37** $QT_END_LICENSE$
38**
39****************************************************************************/
40
41#ifndef QGLOBAL_H
42# include <QtCore/qglobal.h>
43#endif
44
45#ifndef QCOMPILERDETECTION_H
46#define QCOMPILERDETECTION_H
47
48/*
49 The compiler, must be one of: (Q_CC_x)
50
51 SYM - Digital Mars C/C++ (used to be Symantec C++)
52 MSVC - Microsoft Visual C/C++, Intel C++ for Windows
53 BOR - Borland/Turbo C++
54 WAT - Watcom C++
55 GNU - GNU C++
56 COMEAU - Comeau C++
57 EDG - Edison Design Group C++
58 OC - CenterLine C++
59 SUN - Forte Developer, or Sun Studio C++
60 MIPS - MIPSpro C++
61 DEC - DEC C++
62 HPACC - HP aC++
63 USLC - SCO OUDK and UDK
64 CDS - Reliant C++
65 KAI - KAI C++
66 INTEL - Intel C++ for Linux, Intel C++ for Windows
67 HIGHC - MetaWare High C/C++
68 PGI - Portland Group C++
69 GHS - Green Hills Optimizing C++ Compilers
70 RVCT - ARM Realview Compiler Suite
71 CLANG - C++ front-end for the LLVM compiler
72
73
74 Should be sorted most to least authoritative.
75*/
76
77/* Symantec C++ is now Digital Mars */
78#if defined(__DMC__) || defined(__SC__)
79# define Q_CC_SYM
80/* "explicit" semantics implemented in 8.1e but keyword recognized since 7.5 */
81# if defined(__SC__) && __SC__ < 0x750
82# error "Compiler not supported"
83# endif
84
85#elif defined(_MSC_VER)
86# ifdef __clang__
87# define Q_CC_CLANG ((__clang_major__ * 100) + __clang_minor__)
88# endif
89# define Q_CC_MSVC (_MSC_VER)
90# define Q_CC_MSVC_NET
91# define Q_OUTOFLINE_TEMPLATE inline
92# define Q_COMPILER_MANGLES_RETURN_TYPE
93# define Q_FUNC_INFO __FUNCSIG__
94# define Q_ASSUME_IMPL(expr) __assume(expr)
95# define Q_UNREACHABLE_IMPL() __assume(0)
96# define Q_NORETURN __declspec(noreturn)
97# define Q_DECL_DEPRECATED __declspec(deprecated)
98# ifndef Q_CC_CLANG
99# define Q_DECL_DEPRECATED_X(text) __declspec(deprecated(text))
100# endif
101# define Q_DECL_EXPORT __declspec(dllexport)
102# define Q_DECL_IMPORT __declspec(dllimport)
103# define QT_MAKE_UNCHECKED_ARRAY_ITERATOR(x) stdext::make_unchecked_array_iterator(x) // Since _MSC_VER >= 1800
104# define QT_MAKE_CHECKED_ARRAY_ITERATOR(x, N) stdext::make_checked_array_iterator(x, size_t(N)) // Since _MSC_VER >= 1500
105/* Intel C++ disguising as Visual C++: the `using' keyword avoids warnings */
106# if defined(__INTEL_COMPILER)
107# define Q_DECL_VARIABLE_DEPRECATED
108# define Q_CC_INTEL __INTEL_COMPILER
109# endif
110
111#elif defined(__BORLANDC__) || defined(__TURBOC__)
112# define Q_CC_BOR
113# define Q_INLINE_TEMPLATE
114# if __BORLANDC__ < 0x502
115# error "Compiler not supported"
116# endif
117
118#elif defined(__WATCOMC__)
119# define Q_CC_WAT
120
121/* ARM Realview Compiler Suite
122 RVCT compiler also defines __EDG__ and __GNUC__ (if --gnu flag is given),
123 so check for it before that */
124#elif defined(__ARMCC__) || defined(__CC_ARM)
125# define Q_CC_RVCT
126/* work-around for missing compiler intrinsics */
127# define __is_empty(X) false
128# define __is_pod(X) false
129# define Q_DECL_DEPRECATED __attribute__ ((__deprecated__))
130# ifdef Q_OS_LINUX
131# define Q_DECL_EXPORT __attribute__((visibility("default")))
132# define Q_DECL_IMPORT __attribute__((visibility("default")))
133# define Q_DECL_HIDDEN __attribute__((visibility("hidden")))
134# else
135# define Q_DECL_EXPORT __declspec(dllexport)
136# define Q_DECL_IMPORT __declspec(dllimport)
137# endif
138
139#elif defined(__GNUC__)
140# define Q_CC_GNU (__GNUC__ * 100 + __GNUC_MINOR__)
141# if defined(__MINGW32__)
142# define Q_CC_MINGW
143# endif
144# if defined(__INTEL_COMPILER)
145/* Intel C++ also masquerades as GCC */
146# define Q_CC_INTEL (__INTEL_COMPILER)
147# ifdef __clang__
148/* Intel C++ masquerades as Clang masquerading as GCC */
149# define Q_CC_CLANG 305
150# endif
151# define Q_ASSUME_IMPL(expr) __assume(expr)
152# define Q_UNREACHABLE_IMPL() __builtin_unreachable()
153# if __INTEL_COMPILER >= 1300 && !defined(__APPLE__)
154# define Q_DECL_DEPRECATED_X(text) __attribute__ ((__deprecated__(text)))
155# endif
156# elif defined(__clang__)
157/* Clang also masquerades as GCC */
158# if defined(__apple_build_version__)
159# /* http://en.wikipedia.org/wiki/Xcode#Toolchain_Versions */
160# if __apple_build_version__ >= 8020041
161# define Q_CC_CLANG 309
162# elif __apple_build_version__ >= 8000038
163# define Q_CC_CLANG 308
164# elif __apple_build_version__ >= 7000053
165# define Q_CC_CLANG 306
166# elif __apple_build_version__ >= 6000051
167# define Q_CC_CLANG 305
168# elif __apple_build_version__ >= 5030038
169# define Q_CC_CLANG 304
170# elif __apple_build_version__ >= 5000275
171# define Q_CC_CLANG 303
172# elif __apple_build_version__ >= 4250024
173# define Q_CC_CLANG 302
174# elif __apple_build_version__ >= 3180045
175# define Q_CC_CLANG 301
176# elif __apple_build_version__ >= 2111001
177# define Q_CC_CLANG 300
178# else
179# error "Unknown Apple Clang version"
180# endif
181# else
182# define Q_CC_CLANG ((__clang_major__ * 100) + __clang_minor__)
183# endif
184# if __has_builtin(__builtin_assume)
185# define Q_ASSUME_IMPL(expr) __builtin_assume(expr)
186# else
187# define Q_ASSUME_IMPL(expr) if (expr){} else __builtin_unreachable()
188# endif
189# define Q_UNREACHABLE_IMPL() __builtin_unreachable()
190# if !defined(__has_extension)
191# /* Compatibility with older Clang versions */
192# define __has_extension __has_feature
193# endif
194# if defined(__APPLE__)
195 /* Apple/clang specific features */
196# define Q_DECL_CF_RETURNS_RETAINED __attribute__((cf_returns_retained))
197# ifdef __OBJC__
198# define Q_DECL_NS_RETURNS_AUTORELEASED __attribute__((ns_returns_autoreleased))
199# endif
200# endif
201# ifdef __EMSCRIPTEN__
202# define Q_CC_EMSCRIPTEN
203# endif
204# else
205/* Plain GCC */
206# if Q_CC_GNU >= 405
207# define Q_ASSUME_IMPL(expr) if (expr){} else __builtin_unreachable()
208# define Q_UNREACHABLE_IMPL() __builtin_unreachable()
209# define Q_DECL_DEPRECATED_X(text) __attribute__ ((__deprecated__(text)))
210# endif
211# endif
212
213# ifdef Q_OS_WIN
214# define Q_DECL_EXPORT __declspec(dllexport)
215# define Q_DECL_IMPORT __declspec(dllimport)
216# elif defined(QT_VISIBILITY_AVAILABLE)
217# define Q_DECL_EXPORT __attribute__((visibility("default")))
218# define Q_DECL_IMPORT __attribute__((visibility("default")))
219# define Q_DECL_HIDDEN __attribute__((visibility("hidden")))
220# endif
221
222# define Q_FUNC_INFO __PRETTY_FUNCTION__
223# define Q_TYPEOF(expr) __typeof__(expr)
224# define Q_DECL_DEPRECATED __attribute__ ((__deprecated__))
225# define Q_DECL_UNUSED __attribute__((__unused__))
226# define Q_LIKELY(expr) __builtin_expect(!!(expr), true)
227# define Q_UNLIKELY(expr) __builtin_expect(!!(expr), false)
228# define Q_NORETURN __attribute__((__noreturn__))
229# define Q_REQUIRED_RESULT __attribute__ ((__warn_unused_result__))
230# define Q_DECL_PURE_FUNCTION __attribute__((pure))
231# define Q_DECL_CONST_FUNCTION __attribute__((const))
232# define Q_DECL_COLD_FUNCTION __attribute__((cold))
233# if !defined(QT_MOC_CPP)
234# define Q_PACKED __attribute__ ((__packed__))
235# ifndef __ARM_EABI__
236# define QT_NO_ARM_EABI
237# endif
238# endif
239# if Q_CC_GNU >= 403 && !defined(Q_CC_CLANG)
240# define Q_ALLOC_SIZE(x) __attribute__((alloc_size(x)))
241# endif
242
243/* IBM compiler versions are a bit messy. There are actually two products:
244 the C product, and the C++ product. The C++ compiler is always packaged
245 with the latest version of the C compiler. Version numbers do not always
246 match. This little table (I'm not sure it's accurate) should be helpful:
247
248 C++ product C product
249
250 C Set 3.1 C Compiler 3.0
251 ... ...
252 C++ Compiler 3.6.6 C Compiler 4.3
253 ... ...
254 Visual Age C++ 4.0 ...
255 ... ...
256 Visual Age C++ 5.0 C Compiler 5.0
257 ... ...
258 Visual Age C++ 6.0 C Compiler 6.0
259
260 Now:
261 __xlC__ is the version of the C compiler in hexadecimal notation
262 is only an approximation of the C++ compiler version
263 __IBMCPP__ is the version of the C++ compiler in decimal notation
264 but it is not defined on older compilers like C Set 3.1 */
265#elif defined(__xlC__)
266# define Q_CC_XLC
267# define Q_FULL_TEMPLATE_INSTANTIATION
268# if __xlC__ < 0x400
269# error "Compiler not supported"
270# elif __xlC__ >= 0x0600
271# define Q_TYPEOF(expr) __typeof__(expr)
272# define Q_PACKED __attribute__((__packed__))
273# endif
274
275/* Older versions of DEC C++ do not define __EDG__ or __EDG - observed
276 on DEC C++ V5.5-004. New versions do define __EDG__ - observed on
277 Compaq C++ V6.3-002.
278 This compiler is different enough from other EDG compilers to handle
279 it separately anyway. */
280#elif defined(__DECCXX) || defined(__DECC)
281# define Q_CC_DEC
282/* Compaq C++ V6 compilers are EDG-based but I'm not sure about older
283 DEC C++ V5 compilers. */
284# if defined(__EDG__)
285# define Q_CC_EDG
286# endif
287/* Compaq has disabled EDG's _BOOL macro and uses _BOOL_EXISTS instead
288 - observed on Compaq C++ V6.3-002.
289 In any case versions prior to Compaq C++ V6.0-005 do not have bool. */
290# if !defined(_BOOL_EXISTS)
291# error "Compiler not supported"
292# endif
293/* Spurious (?) error messages observed on Compaq C++ V6.5-014. */
294/* Apply to all versions prior to Compaq C++ V6.0-000 - observed on
295 DEC C++ V5.5-004. */
296# if __DECCXX_VER < 60060000
297# define Q_BROKEN_TEMPLATE_SPECIALIZATION
298# endif
299/* avoid undefined symbol problems with out-of-line template members */
300# define Q_OUTOFLINE_TEMPLATE inline
301
302/* The Portland Group C++ compiler is based on EDG and does define __EDG__
303 but the C compiler does not */
304#elif defined(__PGI)
305# define Q_CC_PGI
306# if defined(__EDG__)
307# define Q_CC_EDG
308# endif
309
310/* Compilers with EDG front end are similar. To detect them we test:
311 __EDG documented by SGI, observed on MIPSpro 7.3.1.1 and KAI C++ 4.0b
312 __EDG__ documented in EDG online docs, observed on Compaq C++ V6.3-002
313 and PGI C++ 5.2-4 */
314#elif !defined(Q_OS_HPUX) && (defined(__EDG) || defined(__EDG__))
315# define Q_CC_EDG
316/* From the EDG documentation (does not seem to apply to Compaq C++ or GHS C):
317 _BOOL
318 Defined in C++ mode when bool is a keyword. The name of this
319 predefined macro is specified by a configuration flag. _BOOL
320 is the default.
321 __BOOL_DEFINED
322 Defined in Microsoft C++ mode when bool is a keyword. */
323# if !defined(_BOOL) && !defined(__BOOL_DEFINED) && !defined(__ghs)
324# error "Compiler not supported"
325# endif
326
327/* The Comeau compiler is based on EDG and does define __EDG__ */
328# if defined(__COMO__)
329# define Q_CC_COMEAU
330
331/* The `using' keyword was introduced to avoid KAI C++ warnings
332 but it's now causing KAI C++ errors instead. The standard is
333 unclear about the use of this keyword, and in practice every
334 compiler is using its own set of rules. Forget it. */
335# elif defined(__KCC)
336# define Q_CC_KAI
337
338/* Using the `using' keyword avoids Intel C++ for Linux warnings */
339# elif defined(__INTEL_COMPILER)
340# define Q_CC_INTEL (__INTEL_COMPILER)
341
342/* Uses CFront, make sure to read the manual how to tweak templates. */
343# elif defined(__ghs)
344# define Q_CC_GHS
345# define Q_DECL_DEPRECATED __attribute__ ((__deprecated__))
346# define Q_PACKED __attribute__ ((__packed__))
347# define Q_FUNC_INFO __PRETTY_FUNCTION__
348# define Q_TYPEOF(expr) __typeof__(expr)
349# define Q_UNREACHABLE_IMPL()
350# if defined(__cplusplus)
351# define Q_COMPILER_AUTO_TYPE
352# define Q_COMPILER_STATIC_ASSERT
353# define Q_COMPILER_RANGE_FOR
354# if __GHS_VERSION_NUMBER >= 201505
355# define Q_COMPILER_ALIGNAS
356# define Q_COMPILER_ALIGNOF
357# define Q_COMPILER_ATOMICS
358# define Q_COMPILER_ATTRIBUTES
359# define Q_COMPILER_AUTO_FUNCTION
360# define Q_COMPILER_CLASS_ENUM
361# define Q_COMPILER_DECLTYPE
362# define Q_COMPILER_DEFAULT_MEMBERS
363# define Q_COMPILER_DELETE_MEMBERS
364# define Q_COMPILER_DELEGATING_CONSTRUCTORS
365# define Q_COMPILER_EXPLICIT_CONVERSIONS
366# define Q_COMPILER_EXPLICIT_OVERRIDES
367# define Q_COMPILER_EXTERN_TEMPLATES
368# define Q_COMPILER_INHERITING_CONSTRUCTORS
369# define Q_COMPILER_INITIALIZER_LISTS
370# define Q_COMPILER_LAMBDA
371# define Q_COMPILER_NONSTATIC_MEMBER_INIT
372# define Q_COMPILER_NOEXCEPT
373# define Q_COMPILER_NULLPTR
374# define Q_COMPILER_RANGE_FOR
375# define Q_COMPILER_RAW_STRINGS
376# define Q_COMPILER_REF_QUALIFIERS
377# define Q_COMPILER_RVALUE_REFS
378# define Q_COMPILER_STATIC_ASSERT
379# define Q_COMPILER_TEMPLATE_ALIAS
380# define Q_COMPILER_THREAD_LOCAL
381# define Q_COMPILER_UDL
382# define Q_COMPILER_UNICODE_STRINGS
383# define Q_COMPILER_UNIFORM_INIT
384# define Q_COMPILER_UNRESTRICTED_UNIONS
385# define Q_COMPILER_VARIADIC_MACROS
386# define Q_COMPILER_VARIADIC_TEMPLATES
387# endif
388# endif //__cplusplus
389
390# elif defined(__DCC__)
391# define Q_CC_DIAB
392# if !defined(__bool)
393# error "Compiler not supported"
394# endif
395
396/* The UnixWare 7 UDK compiler is based on EDG and does define __EDG__ */
397# elif defined(__USLC__) && defined(__SCO_VERSION__)
398# define Q_CC_USLC
399/* The latest UDK 7.1.1b does not need this, but previous versions do */
400# if !defined(__SCO_VERSION__) || (__SCO_VERSION__ < 302200010)
401# define Q_OUTOFLINE_TEMPLATE inline
402# endif
403
404/* Never tested! */
405# elif defined(CENTERLINE_CLPP) || defined(OBJECTCENTER)
406# define Q_CC_OC
407
408/* CDS++ defines __EDG__ although this is not documented in the Reliant
409 documentation. It also follows conventions like _BOOL and this documented */
410# elif defined(sinix)
411# define Q_CC_CDS
412
413/* The MIPSpro compiler defines __EDG */
414# elif defined(__sgi)
415# define Q_CC_MIPS
416# define Q_NO_TEMPLATE_FRIENDS
417# if defined(_COMPILER_VERSION) && (_COMPILER_VERSION >= 740)
418# define Q_OUTOFLINE_TEMPLATE inline
419# pragma set woff 3624,3625,3649 /* turn off some harmless warnings */
420# endif
421# endif
422
423/* VxWorks' DIAB toolchain has an additional EDG type C++ compiler
424 (see __DCC__ above). This one is for C mode files (__EDG is not defined) */
425#elif defined(_DIAB_TOOL)
426# define Q_CC_DIAB
427# define Q_FUNC_INFO __PRETTY_FUNCTION__
428
429/* Never tested! */
430#elif defined(__HIGHC__)
431# define Q_CC_HIGHC
432
433#elif defined(__SUNPRO_CC) || defined(__SUNPRO_C)
434# define Q_CC_SUN
435# define Q_COMPILER_MANGLES_RETURN_TYPE
436/* 5.0 compiler or better
437 'bool' is enabled by default but can be disabled using -features=nobool
438 in which case _BOOL is not defined
439 this is the default in 4.2 compatibility mode triggered by -compat=4 */
440# if __SUNPRO_CC >= 0x500
441# define QT_NO_TEMPLATE_TEMPLATE_PARAMETERS
442 /* see http://developers.sun.com/sunstudio/support/Ccompare.html */
443# if __SUNPRO_CC >= 0x590
444# define Q_TYPEOF(expr) __typeof__(expr)
445# endif
446# if __SUNPRO_CC >= 0x550
447# define Q_DECL_EXPORT __global
448# endif
449# if __SUNPRO_CC < 0x5a0
450# define Q_NO_TEMPLATE_FRIENDS
451# endif
452# if !defined(_BOOL)
453# error "Compiler not supported"
454# endif
455/* 4.2 compiler or older */
456# else
457# error "Compiler not supported"
458# endif
459
460/* CDS++ does not seem to define __EDG__ or __EDG according to Reliant
461 documentation but nevertheless uses EDG conventions like _BOOL */
462#elif defined(sinix)
463# define Q_CC_EDG
464# define Q_CC_CDS
465# if !defined(_BOOL)
466# error "Compiler not supported"
467# endif
468# define Q_BROKEN_TEMPLATE_SPECIALIZATION
469
470#elif defined(Q_OS_HPUX)
471/* __HP_aCC was not defined in first aCC releases */
472# if defined(__HP_aCC) || __cplusplus >= 199707L
473# define Q_NO_TEMPLATE_FRIENDS
474# define Q_CC_HPACC
475# define Q_FUNC_INFO __PRETTY_FUNCTION__
476# if __HP_aCC-0 < 060000
477# define QT_NO_TEMPLATE_TEMPLATE_PARAMETERS
478# define Q_DECL_EXPORT __declspec(dllexport)
479# define Q_DECL_IMPORT __declspec(dllimport)
480# endif
481# if __HP_aCC-0 >= 062000
482# define Q_DECL_EXPORT __attribute__((visibility("default")))
483# define Q_DECL_HIDDEN __attribute__((visibility("hidden")))
484# define Q_DECL_IMPORT Q_DECL_EXPORT
485# endif
486# else
487# error "Compiler not supported"
488# endif
489
490#else
491# error "Qt has not been tested with this compiler - see http://www.qt-project.org/"
492#endif
493
494/*
495 * SG10's SD-6 feature detection and some useful extensions from Clang and GCC
496 * https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations
497 * http://clang.llvm.org/docs/LanguageExtensions.html#feature-checking-macros
498 * Not using wrapper macros, per http://eel.is/c++draft/cpp.cond#7.sentence-2
499 */
500#ifndef __has_builtin
501# define __has_builtin(x) 0
502#endif
503#ifndef __has_feature
504# define __has_feature(x) 0
505#endif
506#ifndef __has_attribute
507# define __has_attribute(x) 0
508#endif
509#ifndef __has_cpp_attribute
510# define __has_cpp_attribute(x) 0
511#endif
512#ifndef __has_include
513# define __has_include(x) 0
514#endif
515#ifndef __has_include_next
516# define __has_include_next(x) 0
517#endif
518
519// Kept around until all submodules have transitioned
520#define QT_HAS_BUILTIN(x) __has_builtin(x)
521#define QT_HAS_FEATURE(x) __has_feature(x)
522#define QT_HAS_ATTRIBUTE(x) __has_attribute(x)
523#define QT_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
524#define QT_HAS_INCLUDE(x) __has_include(x)
525#define QT_HAS_INCLUDE_NEXT(x) __has_include_next(x)
526
527/*
528 * C++11 support
529 *
530 * Paper Macro SD-6 macro
531 * N2341 Q_COMPILER_ALIGNAS
532 * N2341 Q_COMPILER_ALIGNOF
533 * N2427 Q_COMPILER_ATOMICS
534 * N2761 Q_COMPILER_ATTRIBUTES __cpp_attributes = 200809
535 * N2541 Q_COMPILER_AUTO_FUNCTION
536 * N1984 N2546 Q_COMPILER_AUTO_TYPE
537 * N2437 Q_COMPILER_CLASS_ENUM
538 * N2235 Q_COMPILER_CONSTEXPR __cpp_constexpr = 200704
539 * N2343 N3276 Q_COMPILER_DECLTYPE __cpp_decltype = 200707
540 * N2346 Q_COMPILER_DEFAULT_MEMBERS
541 * N2346 Q_COMPILER_DELETE_MEMBERS
542 * N1986 Q_COMPILER_DELEGATING_CONSTRUCTORS
543 * N2437 Q_COMPILER_EXPLICIT_CONVERSIONS
544 * N3206 N3272 Q_COMPILER_EXPLICIT_OVERRIDES
545 * N1987 Q_COMPILER_EXTERN_TEMPLATES
546 * N2540 Q_COMPILER_INHERITING_CONSTRUCTORS
547 * N2672 Q_COMPILER_INITIALIZER_LISTS
548 * N2658 N2927 Q_COMPILER_LAMBDA __cpp_lambdas = 200907
549 * N2756 Q_COMPILER_NONSTATIC_MEMBER_INIT
550 * N2855 N3050 Q_COMPILER_NOEXCEPT
551 * N2431 Q_COMPILER_NULLPTR
552 * N2930 Q_COMPILER_RANGE_FOR
553 * N2442 Q_COMPILER_RAW_STRINGS __cpp_raw_strings = 200710
554 * N2439 Q_COMPILER_REF_QUALIFIERS
555 * N2118 N2844 N3053 Q_COMPILER_RVALUE_REFS __cpp_rvalue_references = 200610
556 * N1720 Q_COMPILER_STATIC_ASSERT __cpp_static_assert = 200410
557 * N2258 Q_COMPILER_TEMPLATE_ALIAS
558 * N2659 Q_COMPILER_THREAD_LOCAL
559 * N2660 Q_COMPILER_THREADSAFE_STATICS
560 * N2765 Q_COMPILER_UDL __cpp_user_defined_literals = 200809
561 * N2442 Q_COMPILER_UNICODE_STRINGS __cpp_unicode_literals = 200710
562 * N2640 Q_COMPILER_UNIFORM_INIT
563 * N2544 Q_COMPILER_UNRESTRICTED_UNIONS
564 * N1653 Q_COMPILER_VARIADIC_MACROS
565 * N2242 N2555 Q_COMPILER_VARIADIC_TEMPLATES __cpp_variadic_templates = 200704
566 *
567 * For any future version of the C++ standard, we use only the SD-6 macro.
568 * For full listing, see
569 * http://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations
570 *
571 * C++ extensions:
572 * Q_COMPILER_RESTRICTED_VLA variable-length arrays, prior to __cpp_runtime_arrays
573 */
574
575/*
576 * Now that we require C++17, we unconditionally expect threadsafe statics mandated since C++11
577 */
578#define Q_COMPILER_THREADSAFE_STATICS
579
580#ifdef __cplusplus
581# if __cplusplus < 201103L && !defined(Q_CC_MSVC)
582# error Qt requires a C++11 compiler and yours does not seem to be that.
583# endif
584#endif
585
586#if defined(Q_CC_INTEL) && !defined(Q_CC_MSVC)
587# define Q_COMPILER_RESTRICTED_VLA
588# define Q_COMPILER_VARIADIC_MACROS // C++11 feature supported as an extension in other modes, too
589# if __INTEL_COMPILER < 1200
590# define Q_NO_TEMPLATE_FRIENDS
591# endif
592# if __INTEL_COMPILER >= 1310 && !defined(_WIN32)
593// ICC supports C++14 binary literals in C, C++98, and C++11 modes
594// at least since 13.1, but I can't test further back
595# define Q_COMPILER_BINARY_LITERALS
596# endif
597# if __cplusplus >= 201103L || defined(__INTEL_CXX11_MODE__)
598# if __INTEL_COMPILER >= 1200
599# define Q_COMPILER_AUTO_TYPE
600# define Q_COMPILER_CLASS_ENUM
601# define Q_COMPILER_DECLTYPE
602# define Q_COMPILER_DEFAULT_MEMBERS
603# define Q_COMPILER_DELETE_MEMBERS
604# define Q_COMPILER_EXTERN_TEMPLATES
605# define Q_COMPILER_LAMBDA
606# define Q_COMPILER_RVALUE_REFS
607# define Q_COMPILER_STATIC_ASSERT
608# define Q_COMPILER_VARIADIC_MACROS
609# endif
610# if __INTEL_COMPILER >= 1210
611# define Q_COMPILER_ATTRIBUTES
612# define Q_COMPILER_AUTO_FUNCTION
613# define Q_COMPILER_NULLPTR
614# define Q_COMPILER_TEMPLATE_ALIAS
615# ifndef _CHAR16T // MSVC headers
616# define Q_COMPILER_UNICODE_STRINGS
617# endif
618# define Q_COMPILER_VARIADIC_TEMPLATES
619# endif
620# if __INTEL_COMPILER >= 1300
621# define Q_COMPILER_ATOMICS
622// constexpr support is only partial
623//# define Q_COMPILER_CONSTEXPR
624# define Q_COMPILER_INITIALIZER_LISTS
625# define Q_COMPILER_UNIFORM_INIT
626# define Q_COMPILER_NOEXCEPT
627# endif
628# if __INTEL_COMPILER >= 1400
629// causes issues with QArrayData and QtPrivate::RefCount - Intel issue ID 6000056211, bug DPD200534796
630//# define Q_COMPILER_CONSTEXPR
631# define Q_COMPILER_DELEGATING_CONSTRUCTORS
632# define Q_COMPILER_EXPLICIT_CONVERSIONS
633# define Q_COMPILER_EXPLICIT_OVERRIDES
634# define Q_COMPILER_NONSTATIC_MEMBER_INIT
635# define Q_COMPILER_RANGE_FOR
636# define Q_COMPILER_RAW_STRINGS
637# define Q_COMPILER_REF_QUALIFIERS
638# define Q_COMPILER_UNICODE_STRINGS
639# define Q_COMPILER_UNRESTRICTED_UNIONS
640# endif
641# if __INTEL_COMPILER >= 1500
642# if __INTEL_COMPILER * 100 + __INTEL_COMPILER_UPDATE >= 150001
643// the bug mentioned above is fixed in 15.0.1
644# define Q_COMPILER_CONSTEXPR
645# endif
646# define Q_COMPILER_ALIGNAS
647# define Q_COMPILER_ALIGNOF
648# define Q_COMPILER_INHERITING_CONSTRUCTORS
649# define Q_COMPILER_THREAD_LOCAL
650# define Q_COMPILER_UDL
651# endif
652# elif defined(__STDC_VERSION__) && __STDC_VERSION__ > 199901L
653// C11 features supported. Only tested with ICC 17 and up.
654# define Q_COMPILER_STATIC_ASSERT
655# if __has_include(<threads.h>)
656# define Q_COMPILER_THREAD_LOCAL
657# endif
658# endif
659#endif
660
661#if defined(Q_CC_CLANG) && !defined(Q_CC_INTEL) && !defined(Q_CC_MSVC)
662/* General C++ features */
663# define Q_COMPILER_RESTRICTED_VLA
664# if __has_feature(attribute_deprecated_with_message)
665# define Q_DECL_DEPRECATED_X(text) __attribute__ ((__deprecated__(text)))
666# endif
667
668// Clang supports binary literals in C, C++98 and C++11 modes
669// It's been supported "since the dawn of time itself" (cf. commit 179883)
670# if __has_extension(cxx_binary_literals)
671# define Q_COMPILER_BINARY_LITERALS
672# endif
673
674// Variadic macros are supported for gnu++98, c++11, c99 ... since 2.9
675# if Q_CC_CLANG >= 209
676# if !defined(__STRICT_ANSI__) || defined(__GXX_EXPERIMENTAL_CXX0X__) \
677 || (defined(__cplusplus) && (__cplusplus >= 201103L)) \
678 || (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L))
679# define Q_COMPILER_VARIADIC_MACROS
680# endif
681# endif
682
683/* C++11 features, see http://clang.llvm.org/cxx_status.html */
684# if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
685 /* Detect C++ features using __has_feature(), see http://clang.llvm.org/docs/LanguageExtensions.html#cxx11 */
686# if __has_feature(cxx_alignas)
687# define Q_COMPILER_ALIGNAS
688# define Q_COMPILER_ALIGNOF
689# endif
690# if __has_feature(cxx_atomic) && __has_include(<atomic>)
691# define Q_COMPILER_ATOMICS
692# endif
693# if __has_feature(cxx_attributes)
694# define Q_COMPILER_ATTRIBUTES
695# endif
696# if __has_feature(cxx_auto_type)
697# define Q_COMPILER_AUTO_FUNCTION
698# define Q_COMPILER_AUTO_TYPE
699# endif
700# if __has_feature(cxx_strong_enums)
701# define Q_COMPILER_CLASS_ENUM
702# endif
703# if __has_feature(cxx_constexpr) && Q_CC_CLANG > 302 /* CLANG 3.2 has bad/partial support */
704# define Q_COMPILER_CONSTEXPR
705# endif
706# if __has_feature(cxx_decltype) /* && __has_feature(cxx_decltype_incomplete_return_types) */
707# define Q_COMPILER_DECLTYPE
708# endif
709# if __has_feature(cxx_defaulted_functions)
710# define Q_COMPILER_DEFAULT_MEMBERS
711# endif
712# if __has_feature(cxx_deleted_functions)
713# define Q_COMPILER_DELETE_MEMBERS
714# endif
715# if __has_feature(cxx_delegating_constructors)
716# define Q_COMPILER_DELEGATING_CONSTRUCTORS
717# endif
718# if __has_feature(cxx_explicit_conversions)
719# define Q_COMPILER_EXPLICIT_CONVERSIONS
720# endif
721# if __has_feature(cxx_override_control)
722# define Q_COMPILER_EXPLICIT_OVERRIDES
723# endif
724# if __has_feature(cxx_inheriting_constructors)
725# define Q_COMPILER_INHERITING_CONSTRUCTORS
726# endif
727# if __has_feature(cxx_generalized_initializers)
728# define Q_COMPILER_INITIALIZER_LISTS
729# define Q_COMPILER_UNIFORM_INIT /* both covered by this feature macro, according to docs */
730# endif
731# if __has_feature(cxx_lambdas)
732# define Q_COMPILER_LAMBDA
733# endif
734# if __has_feature(cxx_noexcept)
735# define Q_COMPILER_NOEXCEPT
736# endif
737# if __has_feature(cxx_nonstatic_member_init)
738# define Q_COMPILER_NONSTATIC_MEMBER_INIT
739# endif
740# if __has_feature(cxx_nullptr)
741# define Q_COMPILER_NULLPTR
742# endif
743# if __has_feature(cxx_range_for)
744# define Q_COMPILER_RANGE_FOR
745# endif
746# if __has_feature(cxx_raw_string_literals)
747# define Q_COMPILER_RAW_STRINGS
748# endif
749# if __has_feature(cxx_reference_qualified_functions)
750# define Q_COMPILER_REF_QUALIFIERS
751# endif
752# if __has_feature(cxx_rvalue_references)
753# define Q_COMPILER_RVALUE_REFS
754# endif
755# if __has_feature(cxx_static_assert)
756# define Q_COMPILER_STATIC_ASSERT
757# endif
758# if __has_feature(cxx_alias_templates)
759# define Q_COMPILER_TEMPLATE_ALIAS
760# endif
761# if __has_feature(cxx_thread_local)
762# if !defined(__FreeBSD__) /* FreeBSD clang fails on __cxa_thread_atexit */
763# define Q_COMPILER_THREAD_LOCAL
764# endif
765# endif
766# if __has_feature(cxx_user_literals)
767# define Q_COMPILER_UDL
768# endif
769# if __has_feature(cxx_unicode_literals)
770# define Q_COMPILER_UNICODE_STRINGS
771# endif
772# if __has_feature(cxx_unrestricted_unions)
773# define Q_COMPILER_UNRESTRICTED_UNIONS
774# endif
775# if __has_feature(cxx_variadic_templates)
776# define Q_COMPILER_VARIADIC_TEMPLATES
777# endif
778 /* Features that have no __has_feature() check */
779# if Q_CC_CLANG >= 209 /* since clang 2.9 */
780# define Q_COMPILER_EXTERN_TEMPLATES
781# endif
782# endif
783
784/* C++1y features, deprecated macros. Do not update this list. */
785# if __cplusplus > 201103L
786//# if __has_feature(cxx_binary_literals)
787//# define Q_COMPILER_BINARY_LITERALS // see above
788//# endif
789# if __has_feature(cxx_generic_lambda)
790# define Q_COMPILER_GENERIC_LAMBDA
791# endif
792# if __has_feature(cxx_init_capture)
793# define Q_COMPILER_LAMBDA_CAPTURES
794# endif
795# if __has_feature(cxx_relaxed_constexpr)
796# define Q_COMPILER_RELAXED_CONSTEXPR_FUNCTIONS
797# endif
798# if __has_feature(cxx_decltype_auto) && __has_feature(cxx_return_type_deduction)
799# define Q_COMPILER_RETURN_TYPE_DEDUCTION
800# endif
801# if __has_feature(cxx_variable_templates)
802# define Q_COMPILER_VARIABLE_TEMPLATES
803# endif
804# if __has_feature(cxx_runtime_array)
805# define Q_COMPILER_VLA
806# endif
807# endif
808
809# if defined(__STDC_VERSION__)
810# if __has_feature(c_static_assert)
811# define Q_COMPILER_STATIC_ASSERT
812# endif
813# if __has_feature(c_thread_local) && __has_include(<threads.h>)
814# if !defined(__FreeBSD__) /* FreeBSD clang fails on __cxa_thread_atexit */
815# define Q_COMPILER_THREAD_LOCAL
816# endif
817# endif
818# endif
819
820#endif // Q_CC_CLANG && !Q_CC_INTEL && !Q_CC_MSVC
821
822#if defined(Q_CC_CLANG) && !defined(Q_CC_INTEL)
823# ifndef Q_DECL_UNUSED
824# define Q_DECL_UNUSED __attribute__((__unused__))
825# endif
826# define Q_DECL_UNUSED_MEMBER Q_DECL_UNUSED
827#endif
828
829#if defined(Q_CC_GNU) && !defined(Q_CC_INTEL) && !defined(Q_CC_CLANG)
830# define Q_COMPILER_RESTRICTED_VLA
831# if Q_CC_GNU >= 403
832// GCC supports binary literals in C, C++98 and C++11 modes
833# define Q_COMPILER_BINARY_LITERALS
834# endif
835# if !defined(__STRICT_ANSI__) || defined(__GXX_EXPERIMENTAL_CXX0X__) \
836 || (defined(__cplusplus) && (__cplusplus >= 201103L)) \
837 || (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L))
838 // Variadic macros are supported for gnu++98, c++11, C99 ... since forever (gcc 2.97)
839# define Q_COMPILER_VARIADIC_MACROS
840# endif
841# if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L
842# if Q_CC_GNU >= 403
843 /* C++11 features supported in GCC 4.3: */
844# define Q_COMPILER_DECLTYPE
845# define Q_COMPILER_RVALUE_REFS
846# define Q_COMPILER_STATIC_ASSERT
847# endif
848# if Q_CC_GNU >= 404
849 /* C++11 features supported in GCC 4.4: */
850# define Q_COMPILER_AUTO_FUNCTION
851# define Q_COMPILER_AUTO_TYPE
852# define Q_COMPILER_EXTERN_TEMPLATES
853# define Q_COMPILER_UNIFORM_INIT
854# define Q_COMPILER_UNICODE_STRINGS
855# define Q_COMPILER_VARIADIC_TEMPLATES
856# endif
857# if Q_CC_GNU >= 405
858 /* C++11 features supported in GCC 4.5: */
859# define Q_COMPILER_EXPLICIT_CONVERSIONS
860 /* GCC 4.4 implements initializer_list but does not define typedefs required
861 * by the standard. */
862# define Q_COMPILER_INITIALIZER_LISTS
863# define Q_COMPILER_LAMBDA
864# define Q_COMPILER_RAW_STRINGS
865# define Q_COMPILER_CLASS_ENUM
866# endif
867# if Q_CC_GNU >= 406
868 /* Pre-4.6 compilers implement a non-final snapshot of N2346, hence default and delete
869 * functions are supported only if they are public. Starting from 4.6, GCC handles
870 * final version - the access modifier is not relevant. */
871# define Q_COMPILER_DEFAULT_MEMBERS
872# define Q_COMPILER_DELETE_MEMBERS
873 /* C++11 features supported in GCC 4.6: */
874# define Q_COMPILER_NULLPTR
875# define Q_COMPILER_UNRESTRICTED_UNIONS
876# define Q_COMPILER_RANGE_FOR
877# endif
878# if Q_CC_GNU >= 407
879 /* GCC 4.4 implemented <atomic> and std::atomic using its old intrinsics.
880 * However, the implementation is incomplete for most platforms until GCC 4.7:
881 * instead, std::atomic would use an external lock. Since we need an std::atomic
882 * that is behavior-compatible with QBasicAtomic, we only enable it here */
883# define Q_COMPILER_ATOMICS
884 /* GCC 4.6.x has problems dealing with noexcept expressions,
885 * so turn the feature on for 4.7 and above, only */
886# define Q_COMPILER_NOEXCEPT
887 /* C++11 features supported in GCC 4.7: */
888# define Q_COMPILER_NONSTATIC_MEMBER_INIT
889# define Q_COMPILER_DELEGATING_CONSTRUCTORS
890# define Q_COMPILER_EXPLICIT_OVERRIDES
891# define Q_COMPILER_TEMPLATE_ALIAS
892# define Q_COMPILER_UDL
893# endif
894# if Q_CC_GNU >= 408
895# define Q_COMPILER_ATTRIBUTES
896# define Q_COMPILER_ALIGNAS
897# define Q_COMPILER_ALIGNOF
898# define Q_COMPILER_INHERITING_CONSTRUCTORS
899# define Q_COMPILER_THREAD_LOCAL
900# if Q_CC_GNU > 408 || __GNUC_PATCHLEVEL__ >= 1
901# define Q_COMPILER_REF_QUALIFIERS
902# endif
903# endif
904# if Q_CC_GNU >= 500
905 /* GCC 4.6 introduces constexpr, but it's bugged (at least) in the whole
906 * 4.x series, see e.g. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57694 */
907# define Q_COMPILER_CONSTEXPR
908# endif
909# endif
910# if __cplusplus > 201103L
911# if Q_CC_GNU >= 409
912 /* C++1y features in GCC 4.9 - deprecated, do not update this list */
913//# define Q_COMPILER_BINARY_LITERALS // already supported since GCC 4.3 as an extension
914# define Q_COMPILER_LAMBDA_CAPTURES
915# define Q_COMPILER_RETURN_TYPE_DEDUCTION
916# endif
917# endif
918# if defined(__STDC_VERSION__) && __STDC_VERSION__ > 199901L
919# if Q_CC_GNU >= 407
920 /* C11 features supported in GCC 4.7: */
921# define Q_COMPILER_STATIC_ASSERT
922# endif
923# if Q_CC_GNU >= 409 && defined(__has_include)
924 /* C11 features supported in GCC 4.9: */
925# if __has_include(<threads.h>)
926# define Q_COMPILER_THREAD_LOCAL
927# endif
928# endif
929# endif
930#endif
931
932#if defined(Q_CC_MSVC)
933# if defined(__cplusplus)
934 /* C++11 features supported in VC8 = VC2005: */
935# define Q_COMPILER_VARIADIC_MACROS
936
937 /* 2005 supports the override and final contextual keywords, in
938 the same positions as the C++11 variants, but 'final' is
939 called 'sealed' instead:
940 http://msdn.microsoft.com/en-us/library/0w2w91tf%28v=vs.80%29.aspx
941 The behavior is slightly different in C++/CLI, which requires the
942 "virtual" keyword to be present too, so don't define for that.
943 So don't define Q_COMPILER_EXPLICIT_OVERRIDES (since it's not
944 the same as the C++11 version), but define the Q_DECL_* flags
945 accordingly. */
946 /* C++11 features supported in VC10 = VC2010: */
947# define Q_COMPILER_AUTO_FUNCTION
948# define Q_COMPILER_AUTO_TYPE
949# define Q_COMPILER_DECLTYPE
950# define Q_COMPILER_EXTERN_TEMPLATES
951# define Q_COMPILER_LAMBDA
952# define Q_COMPILER_NULLPTR
953# define Q_COMPILER_RVALUE_REFS
954# define Q_COMPILER_STATIC_ASSERT
955 /* C++11 features supported in VC11 = VC2012: */
956# define Q_COMPILER_EXPLICIT_OVERRIDES /* ...and use std C++11 now */
957# define Q_COMPILER_CLASS_ENUM
958# define Q_COMPILER_ATOMICS
959 /* C++11 features in VC12 = VC2013 */
960# define Q_COMPILER_DELETE_MEMBERS
961# define Q_COMPILER_DELEGATING_CONSTRUCTORS
962# define Q_COMPILER_EXPLICIT_CONVERSIONS
963# define Q_COMPILER_NONSTATIC_MEMBER_INIT
964# define Q_COMPILER_RAW_STRINGS
965# define Q_COMPILER_TEMPLATE_ALIAS
966# define Q_COMPILER_VARIADIC_TEMPLATES
967# define Q_COMPILER_INITIALIZER_LISTS // VC 12 SP 2 RC
968 /* C++11 features in VC14 = VC2015 */
969# define Q_COMPILER_DEFAULT_MEMBERS
970# define Q_COMPILER_ALIGNAS
971# define Q_COMPILER_ALIGNOF
972# define Q_COMPILER_INHERITING_CONSTRUCTORS
973# define Q_COMPILER_NOEXCEPT
974# define Q_COMPILER_RANGE_FOR
975# define Q_COMPILER_REF_QUALIFIERS
976# define Q_COMPILER_THREAD_LOCAL
977# define Q_COMPILER_UDL
978# define Q_COMPILER_UNICODE_STRINGS
979# define Q_COMPILER_UNRESTRICTED_UNIONS
980# if _MSC_FULL_VER >= 190023419
981# define Q_COMPILER_ATTRIBUTES
982// Almost working, see https://connect.microsoft.com/VisualStudio/feedback/details/2011648
983//# define Q_COMPILER_CONSTEXPR
984# define Q_COMPILER_UNIFORM_INIT
985# endif
986# if _MSC_VER >= 1910
987# define Q_COMPILER_CONSTEXPR
988# endif
989# endif /* __cplusplus */
990#endif /* Q_CC_MSVC */
991
992#ifdef Q_COMPILER_UNICODE_STRINGS
993# define Q_STDLIB_UNICODE_STRINGS
994#elif defined(__cplusplus)
995# error "Qt6 requires Unicode string support in both the compiler and the standard library"
996#endif
997
998#ifdef __cplusplus
999# include <utility>
1000# if defined(Q_OS_QNX)
1001// By default, QNX 7.0 uses libc++ (from LLVM) and
1002// QNX 6.X uses Dinkumware's libcpp. In all versions,
1003// it is also possible to use GNU libstdc++.
1004
1005// For Dinkumware, some features must be disabled
1006// (mostly because of library problems).
1007// Dinkumware is assumed when __GLIBCXX__ (GNU libstdc++)
1008// and _LIBCPP_VERSION (LLVM libc++) are both absent.
1009# if !defined(__GLIBCXX__) && !defined(_LIBCPP_VERSION)
1010
1011// Older versions of libcpp (QNX 650) do not support C++11 features
1012// _HAS_* macros are set to 1 by toolchains that actually include
1013// Dinkum C++11 libcpp.
1014
1015# if !defined(_HAS_CPP0X) || !_HAS_CPP0X
1016// Disable C++11 features that depend on library support
1017# undef Q_COMPILER_INITIALIZER_LISTS
1018# undef Q_COMPILER_RVALUE_REFS
1019# undef Q_COMPILER_REF_QUALIFIERS
1020# undef Q_COMPILER_NOEXCEPT
1021// Disable C++11 library features:
1022# undef Q_STDLIB_UNICODE_STRINGS
1023# endif // !_HAS_CPP0X
1024# if !defined(_HAS_NULLPTR_T) || !_HAS_NULLPTR_T
1025# undef Q_COMPILER_NULLPTR
1026# endif //!_HAS_NULLPTR_T
1027# if !defined(_HAS_CONSTEXPR) || !_HAS_CONSTEXPR
1028// The libcpp is missing constexpr keywords on important functions like std::numeric_limits<>::min()
1029// Disable constexpr support on QNX even if the compiler supports it
1030# undef Q_COMPILER_CONSTEXPR
1031# endif // !_HAS_CONSTEXPR
1032# endif // !__GLIBCXX__ && !_LIBCPP_VERSION
1033# endif // Q_OS_QNX
1034# if (defined(Q_CC_CLANG) || defined(Q_CC_INTEL)) && defined(Q_OS_MAC) && defined(__GNUC_LIBSTD__) \
1035 && ((__GNUC_LIBSTD__-0) * 100 + __GNUC_LIBSTD_MINOR__-0 <= 402)
1036// Apple has not updated libstdc++ since 2007, which means it does not have
1037// <initializer_list> or std::move. Let's disable these features
1038# undef Q_COMPILER_INITIALIZER_LISTS
1039# undef Q_COMPILER_RVALUE_REFS
1040# undef Q_COMPILER_REF_QUALIFIERS
1041// Also disable <atomic>, since it's clearly not there
1042# undef Q_COMPILER_ATOMICS
1043# endif
1044# if defined(Q_CC_CLANG) && defined(Q_CC_INTEL) && Q_CC_INTEL >= 1500
1045// ICC 15.x and 16.0 have their own implementation of std::atomic, which is activated when in Clang mode
1046// (probably because libc++'s <atomic> on OS X failed to compile), but they're missing some
1047// critical definitions. (Reported as Intel Issue ID 6000117277)
1048# define __USE_CONSTEXPR 1
1049# define __USE_NOEXCEPT 1
1050# endif
1051#endif
1052
1053/*
1054 * C++11 keywords and expressions
1055 */
1056#ifdef Q_COMPILER_NULLPTR
1057# define Q_NULLPTR nullptr
1058#else
1059# define Q_NULLPTR NULL
1060#endif
1061
1062#ifdef Q_COMPILER_DEFAULT_MEMBERS
1063# define Q_DECL_EQ_DEFAULT = default
1064#else
1065# define Q_DECL_EQ_DEFAULT
1066#endif
1067
1068#ifdef Q_COMPILER_DELETE_MEMBERS
1069# define Q_DECL_EQ_DELETE = delete
1070#else
1071# define Q_DECL_EQ_DELETE
1072#endif
1073
1074// Don't break code that is already using Q_COMPILER_DEFAULT_DELETE_MEMBERS
1075#if defined(Q_COMPILER_DEFAULT_MEMBERS) && defined(Q_COMPILER_DELETE_MEMBERS)
1076# define Q_COMPILER_DEFAULT_DELETE_MEMBERS
1077#endif
1078
1079#if defined Q_COMPILER_CONSTEXPR
1080# if defined(__cpp_constexpr) && __cpp_constexpr-0 >= 201304
1081# define Q_DECL_CONSTEXPR constexpr
1082# define Q_DECL_RELAXED_CONSTEXPR constexpr
1083# define Q_CONSTEXPR constexpr
1084# define Q_RELAXED_CONSTEXPR constexpr
1085# else
1086# define Q_DECL_CONSTEXPR constexpr
1087# define Q_DECL_RELAXED_CONSTEXPR
1088# define Q_CONSTEXPR constexpr
1089# define Q_RELAXED_CONSTEXPR const
1090# endif
1091#else
1092# define Q_DECL_CONSTEXPR
1093# define Q_DECL_RELAXED_CONSTEXPR
1094# define Q_CONSTEXPR const
1095# define Q_RELAXED_CONSTEXPR const
1096#endif
1097
1098#ifdef Q_COMPILER_EXPLICIT_OVERRIDES
1099# define Q_DECL_OVERRIDE override
1100# define Q_DECL_FINAL final
1101#else
1102# ifndef Q_DECL_OVERRIDE
1103# define Q_DECL_OVERRIDE
1104# endif
1105# ifndef Q_DECL_FINAL
1106# define Q_DECL_FINAL
1107# endif
1108#endif
1109
1110#ifdef Q_COMPILER_NOEXCEPT
1111# define Q_DECL_NOEXCEPT noexcept
1112# define Q_DECL_NOEXCEPT_EXPR(x) noexcept(x)
1113#else
1114# define Q_DECL_NOEXCEPT
1115# define Q_DECL_NOEXCEPT_EXPR(x)
1116#endif
1117#define Q_DECL_NOTHROW Q_DECL_NOEXCEPT
1118
1119#ifndef Q_ALIGNOF
1120# define Q_ALIGNOF(x) alignof(x)
1121#endif
1122
1123#ifndef Q_DECL_ALIGN
1124# define Q_DECL_ALIGN(n) alignas(n)
1125#endif
1126
1127#if __has_cpp_attribute(nodiscard) && (!defined(Q_CC_CLANG) || __cplusplus > 201402L) // P0188R1
1128// Can't use [[nodiscard]] with Clang and C++11/14, see https://bugs.llvm.org/show_bug.cgi?id=33518
1129# undef Q_REQUIRED_RESULT
1130# define Q_REQUIRED_RESULT [[nodiscard]]
1131#endif
1132
1133#if __has_cpp_attribute(maybe_unused)
1134# undef Q_DECL_UNUSED
1135# define Q_DECL_UNUSED [[maybe_unused]]
1136#endif
1137
1138#if __has_cpp_attribute(deprecated)
1139# ifdef Q_DECL_DEPRECATED
1140# undef Q_DECL_DEPRECATED
1141# endif
1142# ifdef Q_DECL_DEPRECATED_X
1143# undef Q_DECL_DEPRECATED_X
1144# endif
1145# define Q_DECL_DEPRECATED [[deprecated]]
1146# define Q_DECL_DEPRECATED_X(x) [[deprecated(x)]]
1147#endif
1148
1149#if defined(__cpp_enumerator_attributes) && __cpp_enumerator_attributes >= 201411
1150# define Q_DECL_ENUMERATOR_DEPRECATED Q_DECL_DEPRECATED
1151# define Q_DECL_ENUMERATOR_DEPRECATED_X(x) Q_DECL_DEPRECATED_X(x)
1152#endif
1153
1154/*
1155 * Fallback macros to certain compiler features
1156 */
1157
1158#ifndef Q_NORETURN
1159# define Q_NORETURN
1160#endif
1161#ifndef Q_LIKELY
1162# define Q_LIKELY(x) (x)
1163#endif
1164#ifndef Q_UNLIKELY
1165# define Q_UNLIKELY(x) (x)
1166#endif
1167#ifndef Q_ASSUME_IMPL
1168# define Q_ASSUME_IMPL(expr) qt_noop()
1169#endif
1170#ifndef Q_UNREACHABLE_IMPL
1171# define Q_UNREACHABLE_IMPL() qt_noop()
1172#endif
1173#ifndef Q_ALLOC_SIZE
1174# define Q_ALLOC_SIZE(x)
1175#endif
1176#ifndef Q_REQUIRED_RESULT
1177# define Q_REQUIRED_RESULT
1178#endif
1179#ifndef Q_DECL_DEPRECATED
1180# define Q_DECL_DEPRECATED
1181#endif
1182#ifndef Q_DECL_VARIABLE_DEPRECATED
1183# define Q_DECL_VARIABLE_DEPRECATED Q_DECL_DEPRECATED
1184#endif
1185#ifndef Q_DECL_DEPRECATED_X
1186# define Q_DECL_DEPRECATED_X(text) Q_DECL_DEPRECATED
1187#endif
1188#ifndef Q_DECL_ENUMERATOR_DEPRECATED
1189# define Q_DECL_ENUMERATOR_DEPRECATED
1190#endif
1191#ifndef Q_DECL_ENUMERATOR_DEPRECATED_X
1192# define Q_DECL_ENUMERATOR_DEPRECATED_X(x)
1193#endif
1194#ifndef Q_DECL_EXPORT
1195# define Q_DECL_EXPORT
1196#endif
1197#ifndef Q_DECL_IMPORT
1198# define Q_DECL_IMPORT
1199#endif
1200#ifndef Q_DECL_HIDDEN
1201# define Q_DECL_HIDDEN
1202#endif
1203#ifndef Q_DECL_UNUSED
1204# define Q_DECL_UNUSED
1205#endif
1206#ifndef Q_DECL_UNUSED_MEMBER
1207# define Q_DECL_UNUSED_MEMBER
1208#endif
1209#ifndef Q_FUNC_INFO
1210# if defined(Q_OS_SOLARIS) || defined(Q_CC_XLC)
1211# define Q_FUNC_INFO __FILE__ "(line number unavailable)"
1212# else
1213# define Q_FUNC_INFO __FILE__ ":" QT_STRINGIFY(__LINE__)
1214# endif
1215#endif
1216#ifndef Q_DECL_CF_RETURNS_RETAINED
1217# define Q_DECL_CF_RETURNS_RETAINED
1218#endif
1219#ifndef Q_DECL_NS_RETURNS_AUTORELEASED
1220# define Q_DECL_NS_RETURNS_AUTORELEASED
1221#endif
1222#ifndef Q_DECL_PURE_FUNCTION
1223# define Q_DECL_PURE_FUNCTION
1224#endif
1225#ifndef Q_DECL_CONST_FUNCTION
1226# define Q_DECL_CONST_FUNCTION Q_DECL_PURE_FUNCTION
1227#endif
1228#ifndef Q_DECL_COLD_FUNCTION
1229# define Q_DECL_COLD_FUNCTION
1230#endif
1231#ifndef QT_MAKE_UNCHECKED_ARRAY_ITERATOR
1232# define QT_MAKE_UNCHECKED_ARRAY_ITERATOR(x) (x)
1233#endif
1234#ifndef QT_MAKE_CHECKED_ARRAY_ITERATOR
1235# define QT_MAKE_CHECKED_ARRAY_ITERATOR(x, N) (x)
1236#endif
1237
1238/*
1239 * "Weak overloads" - makes an otherwise confliciting overload weaker
1240 * (by making it a template)
1241 */
1242#define Q_WEAK_OVERLOAD template <typename = void>
1243
1244/*
1245 * Warning/diagnostic handling
1246 */
1247
1248#define QT_DO_PRAGMA(text) _Pragma(#text)
1249#if defined(Q_CC_INTEL) && defined(Q_CC_MSVC)
1250/* icl.exe: Intel compiler on Windows */
1251# undef QT_DO_PRAGMA /* not needed */
1252# define QT_WARNING_PUSH __pragma(warning(push))
1253# define QT_WARNING_POP __pragma(warning(pop))
1254# define QT_WARNING_DISABLE_MSVC(number)
1255# define QT_WARNING_DISABLE_INTEL(number) __pragma(warning(disable: number))
1256# define QT_WARNING_DISABLE_CLANG(text)
1257# define QT_WARNING_DISABLE_GCC(text)
1258# define QT_WARNING_DISABLE_DEPRECATED QT_WARNING_DISABLE_INTEL(1478 1786)
1259# define QT_WARNING_DISABLE_FLOAT_COMPARE QT_WARNING_DISABLE_INTEL(1572)
1260# define QT_WARNING_DISABLE_INVALID_OFFSETOF
1261#elif defined(Q_CC_INTEL)
1262/* icc: Intel compiler on Linux or OS X */
1263# define QT_WARNING_PUSH QT_DO_PRAGMA(warning(push))
1264# define QT_WARNING_POP QT_DO_PRAGMA(warning(pop))
1265# define QT_WARNING_DISABLE_INTEL(number) QT_DO_PRAGMA(warning(disable: number))
1266# define QT_WARNING_DISABLE_MSVC(number)
1267# define QT_WARNING_DISABLE_CLANG(text)
1268# define QT_WARNING_DISABLE_GCC(text)
1269# define QT_WARNING_DISABLE_DEPRECATED QT_WARNING_DISABLE_INTEL(1478 1786)
1270# define QT_WARNING_DISABLE_FLOAT_COMPARE QT_WARNING_DISABLE_INTEL(1572)
1271# define QT_WARNING_DISABLE_INVALID_OFFSETOF
1272#elif defined(Q_CC_MSVC) && !defined(Q_CC_CLANG)
1273# undef QT_DO_PRAGMA /* not needed */
1274# define QT_WARNING_PUSH __pragma(warning(push))
1275# define QT_WARNING_POP __pragma(warning(pop))
1276# define QT_WARNING_DISABLE_MSVC(number) __pragma(warning(disable: number))
1277# define QT_WARNING_DISABLE_INTEL(number)
1278# define QT_WARNING_DISABLE_CLANG(text)
1279# define QT_WARNING_DISABLE_GCC(text)
1280# define QT_WARNING_DISABLE_DEPRECATED QT_WARNING_DISABLE_MSVC(4996)
1281# define QT_WARNING_DISABLE_FLOAT_COMPARE
1282# define QT_WARNING_DISABLE_INVALID_OFFSETOF
1283#elif defined(Q_CC_CLANG)
1284# define QT_WARNING_PUSH QT_DO_PRAGMA(clang diagnostic push)
1285# define QT_WARNING_POP QT_DO_PRAGMA(clang diagnostic pop)
1286# define QT_WARNING_DISABLE_CLANG(text) QT_DO_PRAGMA(clang diagnostic ignored text)
1287# define QT_WARNING_DISABLE_GCC(text)
1288# define QT_WARNING_DISABLE_INTEL(number)
1289# define QT_WARNING_DISABLE_MSVC(number)
1290# define QT_WARNING_DISABLE_DEPRECATED QT_WARNING_DISABLE_CLANG("-Wdeprecated-declarations")
1291# define QT_WARNING_DISABLE_FLOAT_COMPARE QT_WARNING_DISABLE_CLANG("-Wfloat-equal")
1292# define QT_WARNING_DISABLE_INVALID_OFFSETOF QT_WARNING_DISABLE_CLANG("-Winvalid-offsetof")
1293#elif defined(Q_CC_GNU) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 406)
1294# define QT_WARNING_PUSH QT_DO_PRAGMA(GCC diagnostic push)
1295# define QT_WARNING_POP QT_DO_PRAGMA(GCC diagnostic pop)
1296# define QT_WARNING_DISABLE_GCC(text) QT_DO_PRAGMA(GCC diagnostic ignored text)
1297# define QT_WARNING_DISABLE_CLANG(text)
1298# define QT_WARNING_DISABLE_INTEL(number)
1299# define QT_WARNING_DISABLE_MSVC(number)
1300# define QT_WARNING_DISABLE_DEPRECATED QT_WARNING_DISABLE_GCC("-Wdeprecated-declarations")
1301# define QT_WARNING_DISABLE_FLOAT_COMPARE QT_WARNING_DISABLE_GCC("-Wfloat-equal")
1302# define QT_WARNING_DISABLE_INVALID_OFFSETOF QT_WARNING_DISABLE_GCC("-Winvalid-offsetof")
1303#else // All other compilers, GCC < 4.6 and MSVC < 2008
1304# define QT_WARNING_DISABLE_GCC(text)
1305# define QT_WARNING_PUSH
1306# define QT_WARNING_POP
1307# define QT_WARNING_DISABLE_INTEL(number)
1308# define QT_WARNING_DISABLE_MSVC(number)
1309# define QT_WARNING_DISABLE_CLANG(text)
1310# define QT_WARNING_DISABLE_GCC(text)
1311# define QT_WARNING_DISABLE_DEPRECATED
1312# define QT_WARNING_DISABLE_FLOAT_COMPARE
1313#endif
1314
1315#ifndef QT_IGNORE_DEPRECATIONS
1316#define QT_IGNORE_DEPRECATIONS(statement) \
1317 QT_WARNING_PUSH \
1318 QT_WARNING_DISABLE_DEPRECATED \
1319 statement \
1320 QT_WARNING_POP
1321#endif
1322
1323/*
1324 Proper for-scoping in MIPSpro CC
1325*/
1326#ifndef QT_NO_KEYWORDS
1327# if defined(Q_CC_MIPS) || (defined(Q_CC_HPACC) && defined(__ia64))
1328# define for if (0) {} else for
1329# endif
1330#endif
1331
1332#ifdef Q_COMPILER_RVALUE_REFS
1333#define qMove(x) std::move(x)
1334#else
1335#define qMove(x) (x)
1336#endif
1337
1338#define Q_UNREACHABLE() \
1339 do {\
1340 Q_ASSERT_X(false, "Q_UNREACHABLE()", "Q_UNREACHABLE was reached");\
1341 Q_UNREACHABLE_IMPL();\
1342 } while (false)
1343
1344#define Q_ASSUME(Expr) \
1345 do {\
1346 const bool valueOfExpression = Expr;\
1347 Q_ASSERT_X(valueOfExpression, "Q_ASSUME()", "Assumption in Q_ASSUME(\"" #Expr "\") was not correct");\
1348 Q_ASSUME_IMPL(valueOfExpression);\
1349 } while (false)
1350
1351#if defined(__cplusplus)
1352#if __has_cpp_attribute(clang::fallthrough)
1353# define Q_FALLTHROUGH() [[clang::fallthrough]]
1354#elif __has_cpp_attribute(gnu::fallthrough)
1355# define Q_FALLTHROUGH() [[gnu::fallthrough]]
1356#elif __has_cpp_attribute(fallthrough)
1357# define Q_FALLTHROUGH() [[fallthrough]]
1358#endif
1359#endif
1360#ifndef Q_FALLTHROUGH
1361# if (defined(Q_CC_GNU) && Q_CC_GNU >= 700) && !defined(Q_CC_INTEL)
1362# define Q_FALLTHROUGH() __attribute__((fallthrough))
1363# else
1364# define Q_FALLTHROUGH() (void)0
1365#endif
1366#endif
1367
1368
1369/*
1370 Sanitize compiler feature availability
1371*/
1372#if !defined(Q_PROCESSOR_X86)
1373# undef QT_COMPILER_SUPPORTS_SSE2
1374# undef QT_COMPILER_SUPPORTS_SSE3
1375# undef QT_COMPILER_SUPPORTS_SSSE3
1376# undef QT_COMPILER_SUPPORTS_SSE4_1
1377# undef QT_COMPILER_SUPPORTS_SSE4_2
1378# undef QT_COMPILER_SUPPORTS_AVX
1379# undef QT_COMPILER_SUPPORTS_AVX2
1380# undef QT_COMPILER_SUPPORTS_F16C
1381#endif
1382#if !defined(Q_PROCESSOR_ARM)
1383# undef QT_COMPILER_SUPPORTS_NEON
1384#endif
1385#if !defined(Q_PROCESSOR_MIPS)
1386# undef QT_COMPILER_SUPPORTS_MIPS_DSP
1387# undef QT_COMPILER_SUPPORTS_MIPS_DSPR2
1388#endif
1389
1390#endif // QCOMPILERDETECTION_H
1391