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

source code of qtbase/src/corelib/global/qcompilerdetection.h