1/****************************************************************************
2**
3** Copyright (C) 2020 The Qt Company Ltd.
4** Copyright (C) 2019 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#define QGLOBAL_H
43
44#ifdef __cplusplus
45# include <type_traits>
46# include <cstddef>
47# include <utility>
48# include <cstdint>
49#endif
50#ifndef __ASSEMBLER__
51# include <assert.h>
52# include <stddef.h>
53#endif
54
55/*
56 QT_VERSION is (major << 16) + (minor << 8) + patch.
57*/
58#define QT_VERSION QT_VERSION_CHECK(QT_VERSION_MAJOR, QT_VERSION_MINOR, QT_VERSION_PATCH)
59/*
60 can be used like #if (QT_VERSION >= QT_VERSION_CHECK(4, 4, 0))
61*/
62#define QT_VERSION_CHECK(major, minor, patch) ((major<<16)|(minor<<8)|(patch))
63
64#ifdef QT_BOOTSTRAPPED
65#include <QtCore/qconfig-bootstrapped.h>
66#else
67#include <QtCore/qconfig.h>
68#include <QtCore/qtcore-config.h>
69#endif
70
71/*
72 The QT_CONFIG macro implements a safe compile time check for features of Qt.
73 Features can be in three states:
74 0 or undefined: This will lead to a compile error when testing for it
75 -1: The feature is not available
76 1: The feature is available
77*/
78#define QT_CONFIG(feature) (1/QT_FEATURE_##feature == 1)
79#define QT_REQUIRE_CONFIG(feature) Q_STATIC_ASSERT_X(QT_FEATURE_##feature == 1, "Required feature " #feature " for file " __FILE__ " not available.")
80
81/* These two macros makes it possible to turn the builtin line expander into a
82 * string literal. */
83#define QT_STRINGIFY2(x) #x
84#define QT_STRINGIFY(x) QT_STRINGIFY2(x)
85
86#include <QtCore/qsystemdetection.h>
87#include <QtCore/qprocessordetection.h>
88#include <QtCore/qcompilerdetection.h>
89
90// This could go to the very beginning of this file, but we're using compiler
91// detection, so it's here.
92#if defined(__cplusplus) && (__cplusplus < 201703L)
93# ifdef Q_CC_MSVC
94# 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."
95# else
96# error "Qt requires a C++17 compiler"
97# endif
98#endif // __cplusplus
99
100#if defined (__ELF__)
101# define Q_OF_ELF
102#endif
103#if defined (__MACH__) && defined (__APPLE__)
104# define Q_OF_MACH_O
105#endif
106
107/*
108 Avoid "unused parameter" warnings
109*/
110#define Q_UNUSED(x) (void)x;
111
112#if defined(__cplusplus)
113// Don't use these in C++ mode, use static_assert directly.
114// These are here only to keep old code compiling.
115# define Q_STATIC_ASSERT(Condition) static_assert(bool(Condition), #Condition)
116# define Q_STATIC_ASSERT_X(Condition, Message) static_assert(bool(Condition), Message)
117#elif defined(Q_COMPILER_STATIC_ASSERT)
118// C11 mode - using the _S version in case <assert.h> doesn't do the right thing
119# define Q_STATIC_ASSERT(Condition) _Static_assert(!!(Condition), #Condition)
120# define Q_STATIC_ASSERT_X(Condition, Message) _Static_assert(!!(Condition), Message)
121#else
122// C89 & C99 version
123# define Q_STATIC_ASSERT_PRIVATE_JOIN(A, B) Q_STATIC_ASSERT_PRIVATE_JOIN_IMPL(A, B)
124# define Q_STATIC_ASSERT_PRIVATE_JOIN_IMPL(A, B) A ## B
125# ifdef __COUNTER__
126# define Q_STATIC_ASSERT(Condition) \
127 typedef char Q_STATIC_ASSERT_PRIVATE_JOIN(q_static_assert_result, __COUNTER__) [(Condition) ? 1 : -1];
128# else
129# define Q_STATIC_ASSERT(Condition) \
130 typedef char Q_STATIC_ASSERT_PRIVATE_JOIN(q_static_assert_result, __LINE__) [(Condition) ? 1 : -1];
131# endif /* __COUNTER__ */
132# define Q_STATIC_ASSERT_X(Condition, Message) Q_STATIC_ASSERT(Condition)
133#endif
134
135#ifdef __cplusplus
136
137#include <algorithm>
138
139#if !defined(QT_NAMESPACE) || defined(Q_MOC_RUN) /* user namespace */
140
141# define QT_PREPEND_NAMESPACE(name) ::name
142# define QT_USE_NAMESPACE
143# define QT_BEGIN_NAMESPACE
144# define QT_END_NAMESPACE
145# define QT_BEGIN_INCLUDE_NAMESPACE
146# define QT_END_INCLUDE_NAMESPACE
147#ifndef QT_BEGIN_MOC_NAMESPACE
148# define QT_BEGIN_MOC_NAMESPACE
149#endif
150#ifndef QT_END_MOC_NAMESPACE
151# define QT_END_MOC_NAMESPACE
152#endif
153# define QT_FORWARD_DECLARE_CLASS(name) class name;
154# define QT_FORWARD_DECLARE_STRUCT(name) struct name;
155# define QT_MANGLE_NAMESPACE(name) name
156
157#else /* user namespace */
158
159# define QT_PREPEND_NAMESPACE(name) ::QT_NAMESPACE::name
160# define QT_USE_NAMESPACE using namespace ::QT_NAMESPACE;
161# define QT_BEGIN_NAMESPACE namespace QT_NAMESPACE {
162# define QT_END_NAMESPACE }
163# define QT_BEGIN_INCLUDE_NAMESPACE }
164# define QT_END_INCLUDE_NAMESPACE namespace QT_NAMESPACE {
165#ifndef QT_BEGIN_MOC_NAMESPACE
166# define QT_BEGIN_MOC_NAMESPACE QT_USE_NAMESPACE
167#endif
168#ifndef QT_END_MOC_NAMESPACE
169# define QT_END_MOC_NAMESPACE
170#endif
171# define QT_FORWARD_DECLARE_CLASS(name) \
172 QT_BEGIN_NAMESPACE class name; QT_END_NAMESPACE \
173 using QT_PREPEND_NAMESPACE(name);
174
175# define QT_FORWARD_DECLARE_STRUCT(name) \
176 QT_BEGIN_NAMESPACE struct name; QT_END_NAMESPACE \
177 using QT_PREPEND_NAMESPACE(name);
178
179# define QT_MANGLE_NAMESPACE0(x) x
180# define QT_MANGLE_NAMESPACE1(a, b) a##_##b
181# define QT_MANGLE_NAMESPACE2(a, b) QT_MANGLE_NAMESPACE1(a,b)
182# define QT_MANGLE_NAMESPACE(name) QT_MANGLE_NAMESPACE2( \
183 QT_MANGLE_NAMESPACE0(name), QT_MANGLE_NAMESPACE0(QT_NAMESPACE))
184
185namespace QT_NAMESPACE {}
186
187# ifndef QT_BOOTSTRAPPED
188# ifndef QT_NO_USING_NAMESPACE
189 /*
190 This expands to a "using QT_NAMESPACE" also in _header files_.
191 It is the only way the feature can be used without too much
192 pain, but if people _really_ do not want it they can add
193 DEFINES += QT_NO_USING_NAMESPACE to their .pro files.
194 */
195 QT_USE_NAMESPACE
196# endif
197# endif
198
199#endif /* user namespace */
200
201#else /* __cplusplus */
202
203# define QT_BEGIN_NAMESPACE
204# define QT_END_NAMESPACE
205# define QT_USE_NAMESPACE
206# define QT_BEGIN_INCLUDE_NAMESPACE
207# define QT_END_INCLUDE_NAMESPACE
208
209#endif /* __cplusplus */
210
211#if defined(Q_OS_DARWIN) && !defined(QT_LARGEFILE_SUPPORT)
212# define QT_LARGEFILE_SUPPORT 64
213#endif
214
215#ifndef __ASSEMBLER__
216QT_BEGIN_NAMESPACE
217
218/*
219 Size-dependent types (architechture-dependent byte order)
220
221 Make sure to update QMetaType when changing these typedefs
222*/
223
224typedef signed char qint8; /* 8 bit signed */
225typedef unsigned char quint8; /* 8 bit unsigned */
226typedef short qint16; /* 16 bit signed */
227typedef unsigned short quint16; /* 16 bit unsigned */
228typedef int qint32; /* 32 bit signed */
229typedef unsigned int quint32; /* 32 bit unsigned */
230// Unlike LL / ULL in C++, for historical reasons, we force the
231// result to be of the requested type.
232#ifdef __cplusplus
233# define Q_INT64_C(c) static_cast<long long>(c ## LL) /* signed 64 bit constant */
234# define Q_UINT64_C(c) static_cast<unsigned long long>(c ## ULL) /* unsigned 64 bit constant */
235#else
236# define Q_INT64_C(c) ((long long)(c ## LL)) /* signed 64 bit constant */
237# define Q_UINT64_C(c) ((unsigned long long)(c ## ULL)) /* unsigned 64 bit constant */
238#endif
239typedef long long qint64; /* 64 bit signed */
240typedef unsigned long long quint64; /* 64 bit unsigned */
241
242typedef qint64 qlonglong;
243typedef quint64 qulonglong;
244
245#ifndef __cplusplus
246// In C++ mode, we define below using QIntegerForSize template
247Q_STATIC_ASSERT_X(sizeof(ptrdiff_t) == sizeof(size_t), "Weird ptrdiff_t and size_t definitions");
248typedef ptrdiff_t qptrdiff;
249typedef ptrdiff_t qsizetype;
250typedef ptrdiff_t qintptr;
251typedef size_t quintptr;
252
253#define PRIdQPTRDIFF "td"
254#define PRIiQPTRDIFF "ti"
255
256#define PRIdQSIZETYPE "td"
257#define PRIiQSIZETYPE "ti"
258
259#define PRIdQINTPTR "td"
260#define PRIiQINTPTR "ti"
261
262#define PRIuQUINTPTR "zu"
263#define PRIoQUINTPTR "zo"
264#define PRIxQUINTPTR "zx"
265#define PRIXQUINTPTR "zX"
266#endif
267
268/*
269 Useful type definitions for Qt
270*/
271
272QT_BEGIN_INCLUDE_NAMESPACE
273typedef unsigned char uchar;
274typedef unsigned short ushort;
275typedef unsigned int uint;
276typedef unsigned long ulong;
277QT_END_INCLUDE_NAMESPACE
278
279#if defined(QT_COORD_TYPE)
280typedef QT_COORD_TYPE qreal;
281#else
282typedef double qreal;
283#endif
284
285#if defined(QT_NO_DEPRECATED)
286# undef QT_DEPRECATED
287# undef QT_DEPRECATED_X
288# undef QT_DEPRECATED_VARIABLE
289# undef QT_DEPRECATED_CONSTRUCTOR
290#elif !defined(QT_NO_DEPRECATED_WARNINGS)
291# undef QT_DEPRECATED
292# define QT_DEPRECATED Q_DECL_DEPRECATED
293# undef QT_DEPRECATED_X
294# define QT_DEPRECATED_X(text) Q_DECL_DEPRECATED_X(text)
295# undef QT_DEPRECATED_VARIABLE
296# define QT_DEPRECATED_VARIABLE Q_DECL_VARIABLE_DEPRECATED
297# undef QT_DEPRECATED_CONSTRUCTOR
298# define QT_DEPRECATED_CONSTRUCTOR Q_DECL_CONSTRUCTOR_DEPRECATED explicit
299#else
300# undef QT_DEPRECATED
301# define QT_DEPRECATED
302# undef QT_DEPRECATED_X
303# define QT_DEPRECATED_X(text)
304# undef QT_DEPRECATED_VARIABLE
305# define QT_DEPRECATED_VARIABLE
306# undef QT_DEPRECATED_CONSTRUCTOR
307# define QT_DEPRECATED_CONSTRUCTOR
308# undef Q_DECL_ENUMERATOR_DEPRECATED
309# define Q_DECL_ENUMERATOR_DEPRECATED
310#endif
311
312#ifndef QT_DEPRECATED_WARNINGS_SINCE
313# ifdef QT_DISABLE_DEPRECATED_BEFORE
314# define QT_DEPRECATED_WARNINGS_SINCE QT_DISABLE_DEPRECATED_BEFORE
315# else
316# define QT_DEPRECATED_WARNINGS_SINCE QT_VERSION
317# endif
318#endif
319
320#ifndef QT_DISABLE_DEPRECATED_BEFORE
321#define QT_DISABLE_DEPRECATED_BEFORE QT_VERSION_CHECK(5, 0, 0)
322#endif
323
324/*
325 QT_DEPRECATED_SINCE(major, minor) evaluates as true if the Qt version is greater than
326 the deprecation point specified.
327
328 Use it to specify from which version of Qt a function or class has been deprecated
329
330 Example:
331 #if QT_DEPRECATED_SINCE(5,1)
332 QT_DEPRECATED void deprecatedFunction(); //function deprecated since Qt 5.1
333 #endif
334
335*/
336#ifdef QT_DEPRECATED
337#define QT_DEPRECATED_SINCE(major, minor) (QT_VERSION_CHECK(major, minor, 0) > QT_DISABLE_DEPRECATED_BEFORE)
338#else
339#define QT_DEPRECATED_SINCE(major, minor) 0
340#endif
341
342/*
343 QT_DEPRECATED_VERSION(major, minor) and QT_DEPRECATED_VERSION_X(major, minor, text)
344 outputs a deprecation warning if QT_DEPRECATED_WARNINGS_SINCE is equal or greater
345 than the version specified as major, minor. This makes it possible to deprecate a
346 function without annoying a user who needs to stick at a specified minimum version
347 and therefore can't use the new function.
348*/
349#if QT_DEPRECATED_WARNINGS_SINCE >= QT_VERSION_CHECK(5, 12, 0)
350# define QT_DEPRECATED_VERSION_X_5_12(text) QT_DEPRECATED_X(text)
351# define QT_DEPRECATED_VERSION_5_12 QT_DEPRECATED
352#else
353# define QT_DEPRECATED_VERSION_X_5_12(text)
354# define QT_DEPRECATED_VERSION_5_12
355#endif
356
357#if QT_DEPRECATED_WARNINGS_SINCE >= QT_VERSION_CHECK(5, 13, 0)
358# define QT_DEPRECATED_VERSION_X_5_13(text) QT_DEPRECATED_X(text)
359# define QT_DEPRECATED_VERSION_5_13 QT_DEPRECATED
360#else
361# define QT_DEPRECATED_VERSION_X_5_13(text)
362# define QT_DEPRECATED_VERSION_5_13
363#endif
364
365#if QT_DEPRECATED_WARNINGS_SINCE >= QT_VERSION_CHECK(5, 14, 0)
366# define QT_DEPRECATED_VERSION_X_5_14(text) QT_DEPRECATED_X(text)
367# define QT_DEPRECATED_VERSION_5_14 QT_DEPRECATED
368#else
369# define QT_DEPRECATED_VERSION_X_5_14(text)
370# define QT_DEPRECATED_VERSION_5_14
371#endif
372
373#if QT_DEPRECATED_WARNINGS_SINCE >= QT_VERSION_CHECK(5, 15, 0)
374# define QT_DEPRECATED_VERSION_X_5_15(text) QT_DEPRECATED_X(text)
375# define QT_DEPRECATED_VERSION_5_15 QT_DEPRECATED
376#else
377# define QT_DEPRECATED_VERSION_X_5_15(text)
378# define QT_DEPRECATED_VERSION_5_15
379#endif
380
381#if QT_DEPRECATED_WARNINGS_SINCE >= QT_VERSION_CHECK(6, 0, 0)
382# define QT_DEPRECATED_VERSION_X_6_0(text) QT_DEPRECATED_X(text)
383# define QT_DEPRECATED_VERSION_6_0 QT_DEPRECATED
384#else
385# define QT_DEPRECATED_VERSION_X_6_0(text)
386# define QT_DEPRECATED_VERSION_6_0
387#endif
388
389#if QT_DEPRECATED_WARNINGS_SINCE >= QT_VERSION_CHECK(6, 1, 0)
390# define QT_DEPRECATED_VERSION_X_6_1(text) QT_DEPRECATED_X(text)
391# define QT_DEPRECATED_VERSION_6_1 QT_DEPRECATED
392#else
393# define QT_DEPRECATED_VERSION_X_6_1(text)
394# define QT_DEPRECATED_VERSION_6_1
395#endif
396
397#if QT_DEPRECATED_WARNINGS_SINCE >= QT_VERSION_CHECK(6, 2, 0)
398# define QT_DEPRECATED_VERSION_X_6_2(text) QT_DEPRECATED_X(text)
399# define QT_DEPRECATED_VERSION_6_2 QT_DEPRECATED
400#else
401# define QT_DEPRECATED_VERSION_X_6_2(text)
402# define QT_DEPRECATED_VERSION_6_2
403#endif
404
405#if QT_DEPRECATED_WARNINGS_SINCE >= QT_VERSION_CHECK(6, 3, 0)
406# define QT_DEPRECATED_VERSION_X_6_3(text) QT_DEPRECATED_X(text)
407# define QT_DEPRECATED_VERSION_6_3 QT_DEPRECATED
408#else
409# define QT_DEPRECATED_VERSION_X_6_3(text)
410# define QT_DEPRECATED_VERSION_6_3
411#endif
412
413#if QT_DEPRECATED_WARNINGS_SINCE >= QT_VERSION_CHECK(6, 4, 0)
414# define QT_DEPRECATED_VERSION_X_6_4(text) QT_DEPRECATED_X(text)
415# define QT_DEPRECATED_VERSION_6_4 QT_DEPRECATED
416#else
417# define QT_DEPRECATED_VERSION_X_6_4(text)
418# define QT_DEPRECATED_VERSION_6_4
419#endif
420
421#if QT_DEPRECATED_WARNINGS_SINCE >= QT_VERSION_CHECK(6, 5, 0)
422# define QT_DEPRECATED_VERSION_X_6_5(text) QT_DEPRECATED_X(text)
423# define QT_DEPRECATED_VERSION_6_5 QT_DEPRECATED
424#else
425# define QT_DEPRECATED_VERSION_X_6_5(text)
426# define QT_DEPRECATED_VERSION_6_5
427#endif
428
429#if QT_DEPRECATED_WARNINGS_SINCE >= QT_VERSION_CHECK(6, 6, 0)
430# define QT_DEPRECATED_VERSION_X_6_6(text) QT_DEPRECATED_X(text)
431# define QT_DEPRECATED_VERSION_6_6 QT_DEPRECATED
432#else
433# define QT_DEPRECATED_VERSION_X_6_6(text)
434# define QT_DEPRECATED_VERSION_6_6
435#endif
436
437#define QT_DEPRECATED_VERSION_X_5(minor, text) QT_DEPRECATED_VERSION_X_5_##minor(text)
438#define QT_DEPRECATED_VERSION_X(major, minor, text) QT_DEPRECATED_VERSION_X_##major##_##minor(text)
439
440#define QT_DEPRECATED_VERSION_5(minor) QT_DEPRECATED_VERSION_5_##minor
441#define QT_DEPRECATED_VERSION(major, minor) QT_DEPRECATED_VERSION_##major##_##minor
442
443#ifdef __cplusplus
444// A tag to help mark stuff deprecated (cf. QStringViewLiteral)
445namespace QtPrivate {
446enum class Deprecated_t {};
447constexpr inline Deprecated_t Deprecated = {};
448}
449#endif
450
451/*
452 The Qt modules' export macros.
453 The options are:
454 - defined(QT_STATIC): Qt was built or is being built in static mode
455 - defined(QT_SHARED): Qt was built or is being built in shared/dynamic mode
456 If neither was defined, then QT_SHARED is implied. If Qt was compiled in static
457 mode, QT_STATIC is defined in qconfig.h. In shared mode, QT_STATIC is implied
458 for the bootstrapped tools.
459*/
460
461#ifdef QT_BOOTSTRAPPED
462# ifdef QT_SHARED
463# error "QT_SHARED and QT_BOOTSTRAPPED together don't make sense. Please fix the build"
464# elif !defined(QT_STATIC)
465# define QT_STATIC
466# endif
467#endif
468
469#if defined(QT_SHARED) || !defined(QT_STATIC)
470# ifdef QT_STATIC
471# error "Both QT_SHARED and QT_STATIC defined, please make up your mind"
472# endif
473# ifndef QT_SHARED
474# define QT_SHARED
475# endif
476# if defined(QT_BUILD_CORE_LIB)
477# define Q_CORE_EXPORT Q_DECL_EXPORT
478# else
479# define Q_CORE_EXPORT Q_DECL_IMPORT
480# endif
481#else
482# define Q_CORE_EXPORT
483#endif
484
485/*
486 Some classes do not permit copies to be made of an object. These
487 classes contains a private copy constructor and assignment
488 operator to disable copying (the compiler gives an error message).
489*/
490#define Q_DISABLE_COPY(Class) \
491 Class(const Class &) = delete;\
492 Class &operator=(const Class &) = delete;
493
494#define Q_DISABLE_COPY_MOVE(Class) \
495 Q_DISABLE_COPY(Class) \
496 Class(Class &&) = delete; \
497 Class &operator=(Class &&) = delete;
498
499/*
500 Implementing a move assignment operator using an established
501 technique (move-and-swap, pure swap) is just boilerplate.
502 Here's a couple of *private* macros for convenience.
503
504 To know which one to use:
505
506 * if you don't have a move constructor (*) => use pure swap;
507 * if you have a move constructor, then
508 * if your class holds just memory (no file handles, no user-defined
509 datatypes, etc.) => use pure swap;
510 * use move and swap.
511
512 The preference should always go for the move-and-swap one, as it
513 will deterministically destroy the data previously held in *this,
514 and not "dump" it in the moved-from object (which may then be alive
515 for longer).
516
517 The requirement for either macro is the presence of a member swap(),
518 which any value class that defines its own special member functions
519 should have anyhow.
520
521 (*) Many value classes in Qt do not have move constructors; mostly,
522 the implicitly shared classes using QSharedDataPointer and friends.
523 The reason is mostly historical: those classes require either an
524 out-of-line move constructor, which we could not provide before we
525 made C++11 mandatory (and that we don't like anyhow), or
526 an out-of-line dtor for the Q(E)DSP<Private> member (cf. QPixmap).
527
528 If you can however add a move constructor to a class lacking it,
529 consider doing so, then reevaluate which macro to choose.
530*/
531#define QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(Class) \
532 Class &operator=(Class &&other) noexcept { \
533 Class moved(std::move(other)); \
534 swap(moved); \
535 return *this; \
536 }
537
538#define QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(Class) \
539 Class &operator=(Class &&other) noexcept { \
540 swap(other); \
541 return *this; \
542 }
543
544/*
545 No, this is not an evil backdoor. QT_BUILD_INTERNAL just exports more symbols
546 for Qt's internal unit tests. If you want slower loading times and more
547 symbols that can vanish from version to version, feel free to define QT_BUILD_INTERNAL.
548*/
549#if defined(QT_BUILD_INTERNAL) && defined(QT_BUILDING_QT) && defined(QT_SHARED)
550# define Q_AUTOTEST_EXPORT Q_DECL_EXPORT
551#elif defined(QT_BUILD_INTERNAL) && defined(QT_SHARED)
552# define Q_AUTOTEST_EXPORT Q_DECL_IMPORT
553#else
554# define Q_AUTOTEST_EXPORT
555#endif
556
557#define Q_INIT_RESOURCE(name) \
558 do { extern int QT_MANGLE_NAMESPACE(qInitResources_ ## name) (); \
559 QT_MANGLE_NAMESPACE(qInitResources_ ## name) (); } while (false)
560#define Q_CLEANUP_RESOURCE(name) \
561 do { extern int QT_MANGLE_NAMESPACE(qCleanupResources_ ## name) (); \
562 QT_MANGLE_NAMESPACE(qCleanupResources_ ## name) (); } while (false)
563
564/*
565 * If we're compiling C++ code:
566 * - and this is a non-namespace build, declare qVersion as extern "C"
567 * - and this is a namespace build, declare it as a regular function
568 * (we're already inside QT_BEGIN_NAMESPACE / QT_END_NAMESPACE)
569 * If we're compiling C code, simply declare the function. If Qt was compiled
570 * in a namespace, qVersion isn't callable anyway.
571 */
572#if !defined(QT_NAMESPACE) && defined(__cplusplus) && !defined(Q_QDOC)
573extern "C"
574#endif
575Q_CORE_EXPORT Q_DECL_CONST_FUNCTION const char *qVersion(void) Q_DECL_NOEXCEPT;
576
577#if defined(__cplusplus)
578
579#ifndef Q_CONSTRUCTOR_FUNCTION
580# define Q_CONSTRUCTOR_FUNCTION0(AFUNC) \
581 namespace { \
582 static const struct AFUNC ## _ctor_class_ { \
583 inline AFUNC ## _ctor_class_() { AFUNC(); } \
584 } AFUNC ## _ctor_instance_; \
585 }
586
587# define Q_CONSTRUCTOR_FUNCTION(AFUNC) Q_CONSTRUCTOR_FUNCTION0(AFUNC)
588#endif
589
590#ifndef Q_DESTRUCTOR_FUNCTION
591# define Q_DESTRUCTOR_FUNCTION0(AFUNC) \
592 namespace { \
593 static const struct AFUNC ## _dtor_class_ { \
594 inline AFUNC ## _dtor_class_() { } \
595 inline ~ AFUNC ## _dtor_class_() { AFUNC(); } \
596 } AFUNC ## _dtor_instance_; \
597 }
598# define Q_DESTRUCTOR_FUNCTION(AFUNC) Q_DESTRUCTOR_FUNCTION0(AFUNC)
599#endif
600
601/*
602 quintptr and qptrdiff is guaranteed to be the same size as a pointer, i.e.
603
604 sizeof(void *) == sizeof(quintptr)
605 && sizeof(void *) == sizeof(qptrdiff)
606
607 size_t and qsizetype are not guaranteed to be the same size as a pointer, but
608 they usually are. We actually check for that in qglobal.cpp.
609*/
610template <int> struct QIntegerForSize;
611template <> struct QIntegerForSize<1> { typedef quint8 Unsigned; typedef qint8 Signed; };
612template <> struct QIntegerForSize<2> { typedef quint16 Unsigned; typedef qint16 Signed; };
613template <> struct QIntegerForSize<4> { typedef quint32 Unsigned; typedef qint32 Signed; };
614template <> struct QIntegerForSize<8> { typedef quint64 Unsigned; typedef qint64 Signed; };
615#if defined(Q_CC_GNU) && defined(__SIZEOF_INT128__)
616template <> struct QIntegerForSize<16> { __extension__ typedef unsigned __int128 Unsigned; __extension__ typedef __int128 Signed; };
617#endif
618template <class T> struct QIntegerForSizeof: QIntegerForSize<sizeof(T)> { };
619typedef QIntegerForSize<Q_PROCESSOR_WORDSIZE>::Signed qregisterint;
620typedef QIntegerForSize<Q_PROCESSOR_WORDSIZE>::Unsigned qregisteruint;
621typedef QIntegerForSizeof<void *>::Unsigned quintptr;
622typedef QIntegerForSizeof<void *>::Signed qptrdiff;
623typedef qptrdiff qintptr;
624using qsizetype = QIntegerForSizeof<std::size_t>::Signed;
625
626// These custom definitions are necessary as we're not defining our
627// datatypes in terms of the language ones, but in terms of integer
628// types that have the sime size. For instance, on a 32-bit platform,
629// qptrdiff is int, while ptrdiff_t may be aliased to long; therefore
630// using %td to print a qptrdiff would be wrong (and raise -Wformat
631// warnings), although both int and long have same bit size on that
632// platform.
633//
634// We know that sizeof(size_t) == sizeof(void *) == sizeof(qptrdiff).
635#if SIZE_MAX == 4294967295ULL
636#define PRIuQUINTPTR "u"
637#define PRIoQUINTPTR "o"
638#define PRIxQUINTPTR "x"
639#define PRIXQUINTPTR "X"
640
641#define PRIdQPTRDIFF "d"
642#define PRIiQPTRDIFF "i"
643
644#define PRIdQINTPTR "d"
645#define PRIiQINTPTR "i"
646
647#define PRIdQSIZETYPE "d"
648#define PRIiQSIZETYPE "i"
649#elif SIZE_MAX == 18446744073709551615ULL
650#define PRIuQUINTPTR "llu"
651#define PRIoQUINTPTR "llo"
652#define PRIxQUINTPTR "llx"
653#define PRIXQUINTPTR "llX"
654
655#define PRIdQPTRDIFF "lld"
656#define PRIiQPTRDIFF "lli"
657
658#define PRIdQINTPTR "lld"
659#define PRIiQINTPTR "lli"
660
661#define PRIdQSIZETYPE "lld"
662#define PRIiQSIZETYPE "lli"
663#else
664#error Unsupported platform (unknown value for SIZE_MAX)
665#endif
666
667/* moc compats (signals/slots) */
668#ifndef QT_MOC_COMPAT
669# define QT_MOC_COMPAT
670#else
671# undef QT_MOC_COMPAT
672# define QT_MOC_COMPAT
673#endif
674
675#ifdef QT_ASCII_CAST_WARNINGS
676# define QT_ASCII_CAST_WARN Q_DECL_DEPRECATED_X("Use fromUtf8, QStringLiteral, or QLatin1String")
677#else
678# define QT_ASCII_CAST_WARN
679#endif
680
681#ifdef Q_PROCESSOR_X86_32
682# if defined(Q_CC_GNU)
683# define QT_FASTCALL __attribute__((regparm(3)))
684# elif defined(Q_CC_MSVC)
685# define QT_FASTCALL __fastcall
686# else
687# define QT_FASTCALL
688# endif
689#else
690# define QT_FASTCALL
691#endif
692
693// enable gcc warnings for printf-style functions
694#if defined(Q_CC_GNU) && !defined(__INSURE__)
695# if defined(Q_CC_MINGW) && !defined(Q_CC_CLANG)
696# define Q_ATTRIBUTE_FORMAT_PRINTF(A, B) \
697 __attribute__((format(gnu_printf, (A), (B))))
698# else
699# define Q_ATTRIBUTE_FORMAT_PRINTF(A, B) \
700 __attribute__((format(printf, (A), (B))))
701# endif
702#else
703# define Q_ATTRIBUTE_FORMAT_PRINTF(A, B)
704#endif
705
706#ifdef Q_CC_MSVC
707# define Q_NEVER_INLINE __declspec(noinline)
708# define Q_ALWAYS_INLINE __forceinline
709#elif defined(Q_CC_GNU)
710# define Q_NEVER_INLINE __attribute__((noinline))
711# define Q_ALWAYS_INLINE inline __attribute__((always_inline))
712#else
713# define Q_NEVER_INLINE
714# define Q_ALWAYS_INLINE inline
715#endif
716
717//defines the type for the WNDPROC on windows
718//the alignment needs to be forced for sse2 to not crash with mingw
719#if defined(Q_OS_WIN)
720# if defined(Q_CC_MINGW) && defined(Q_PROCESSOR_X86_32)
721# define QT_ENSURE_STACK_ALIGNED_FOR_SSE __attribute__ ((force_align_arg_pointer))
722# else
723# define QT_ENSURE_STACK_ALIGNED_FOR_SSE
724# endif
725# define QT_WIN_CALLBACK CALLBACK QT_ENSURE_STACK_ALIGNED_FOR_SSE
726#endif
727
728/*
729 Utility macros and inline functions
730*/
731
732template <typename T>
733constexpr inline T qAbs(const T &t) { return t >= 0 ? t : -t; }
734
735// gcc < 10 doesn't have __has_builtin
736#if defined(Q_PROCESSOR_ARM_64) && (__has_builtin(__builtin_round) || defined(Q_CC_GNU)) && !defined(Q_CC_CLANG)
737// ARM64 has a single instruction that can do C++ rounding with conversion to integer.
738// Note current clang versions have non-constexpr __builtin_round, ### allow clang this path when they fix it.
739constexpr inline int qRound(double d)
740{ return int(__builtin_round(d)); }
741constexpr inline int qRound(float f)
742{ return int(__builtin_roundf(f)); }
743constexpr inline qint64 qRound64(double d)
744{ return qint64(__builtin_round(d)); }
745constexpr inline qint64 qRound64(float f)
746{ return qint64(__builtin_roundf(f)); }
747#elif defined(__SSE2__) && (__has_builtin(__builtin_copysign) || defined(Q_CC_GNU))
748// SSE has binary operations directly on floating point making copysign fast
749constexpr inline int qRound(double d)
750{ return int(d + __builtin_copysign(0.5, d)); }
751constexpr inline int qRound(float f)
752{ return int(f + __builtin_copysignf(0.5f, f)); }
753constexpr inline qint64 qRound64(double d)
754{ return qint64(d + __builtin_copysign(0.5, d)); }
755constexpr inline qint64 qRound64(float f)
756{ return qint64(f + __builtin_copysignf(0.5f, f)); }
757#else
758constexpr inline int qRound(double d)
759{ return d >= 0.0 ? int(d + 0.5) : int(d - 0.5); }
760constexpr inline int qRound(float d)
761{ return d >= 0.0f ? int(d + 0.5f) : int(d - 0.5f); }
762
763constexpr inline qint64 qRound64(double d)
764{ return d >= 0.0 ? qint64(d + 0.5) : qint64(d - 0.5); }
765constexpr inline qint64 qRound64(float d)
766{ return d >= 0.0f ? qint64(d + 0.5f) : qint64(d - 0.5f); }
767#endif
768
769namespace QTypeTraits {
770
771namespace detail {
772template<typename T, typename U,
773 typename = std::enable_if_t<std::is_arithmetic_v<T> && std::is_arithmetic_v<U> &&
774 std::is_floating_point_v<T> == std::is_floating_point_v<U> &&
775 std::is_signed_v<T> == std::is_signed_v<U> &&
776 !std::is_same_v<T, bool> && !std::is_same_v<U, bool> &&
777 !std::is_same_v<T, char> && !std::is_same_v<U, char>>>
778struct Promoted
779{
780 using type = decltype(T() + U());
781};
782}
783
784template <typename T, typename U>
785using Promoted = typename detail::Promoted<T, U>::type;
786
787}
788
789template <typename T>
790constexpr inline const T &qMin(const T &a, const T &b) { return (a < b) ? a : b; }
791template <typename T>
792constexpr inline const T &qMax(const T &a, const T &b) { return (a < b) ? b : a; }
793template <typename T>
794constexpr inline const T &qBound(const T &min, const T &val, const T &max)
795{ return qMax(min, qMin(max, val)); }
796template <typename T, typename U>
797constexpr inline QTypeTraits::Promoted<T, U> qMin(const T &a, const U &b)
798{
799 using P = QTypeTraits::Promoted<T, U>;
800 P _a = a;
801 P _b = b;
802 return (_a < _b) ? _a : _b;
803}
804template <typename T, typename U>
805constexpr inline QTypeTraits::Promoted<T, U> qMax(const T &a, const U &b)
806{
807 using P = QTypeTraits::Promoted<T, U>;
808 P _a = a;
809 P _b = b;
810 return (_a < _b) ? _b : _a;
811}
812template <typename T, typename U>
813constexpr inline QTypeTraits::Promoted<T, U> qBound(const T &min, const U &val, const T &max)
814{ return qMax(min, qMin(max, val)); }
815template <typename T, typename U>
816constexpr inline QTypeTraits::Promoted<T, U> qBound(const T &min, const T &val, const U &max)
817{ return qMax(min, qMin(max, val)); }
818template <typename T, typename U>
819constexpr inline QTypeTraits::Promoted<T, U> qBound(const U &min, const T &val, const T &max)
820{ return qMax(min, qMin(max, val)); }
821
822#ifndef Q_FORWARD_DECLARE_OBJC_CLASS
823# ifdef __OBJC__
824# define Q_FORWARD_DECLARE_OBJC_CLASS(classname) @class classname
825# else
826# define Q_FORWARD_DECLARE_OBJC_CLASS(classname) class classname
827# endif
828#endif
829#ifndef Q_FORWARD_DECLARE_CF_TYPE
830# define Q_FORWARD_DECLARE_CF_TYPE(type) typedef const struct __ ## type * type ## Ref
831#endif
832#ifndef Q_FORWARD_DECLARE_MUTABLE_CF_TYPE
833# define Q_FORWARD_DECLARE_MUTABLE_CF_TYPE(type) typedef struct __ ## type * type ## Ref
834#endif
835#ifndef Q_FORWARD_DECLARE_CG_TYPE
836#define Q_FORWARD_DECLARE_CG_TYPE(type) typedef const struct type *type ## Ref;
837#endif
838#ifndef Q_FORWARD_DECLARE_MUTABLE_CG_TYPE
839#define Q_FORWARD_DECLARE_MUTABLE_CG_TYPE(type) typedef struct type *type ## Ref;
840#endif
841
842#ifdef Q_OS_DARWIN
843# define QT_DARWIN_PLATFORM_SDK_EQUAL_OR_ABOVE(macos, ios, tvos, watchos) \
844 ((defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && macos != __MAC_NA && __MAC_OS_X_VERSION_MAX_ALLOWED >= macos) || \
845 (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && ios != __IPHONE_NA && __IPHONE_OS_VERSION_MAX_ALLOWED >= ios) || \
846 (defined(__TV_OS_VERSION_MAX_ALLOWED) && tvos != __TVOS_NA && __TV_OS_VERSION_MAX_ALLOWED >= tvos) || \
847 (defined(__WATCH_OS_VERSION_MAX_ALLOWED) && watchos != __WATCHOS_NA && __WATCH_OS_VERSION_MAX_ALLOWED >= watchos))
848
849# define QT_DARWIN_DEPLOYMENT_TARGET_BELOW(macos, ios, tvos, watchos) \
850 ((defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && macos != __MAC_NA && __MAC_OS_X_VERSION_MIN_REQUIRED < macos) || \
851 (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && ios != __IPHONE_NA && __IPHONE_OS_VERSION_MIN_REQUIRED < ios) || \
852 (defined(__TV_OS_VERSION_MIN_REQUIRED) && tvos != __TVOS_NA && __TV_OS_VERSION_MIN_REQUIRED < tvos) || \
853 (defined(__WATCH_OS_VERSION_MIN_REQUIRED) && watchos != __WATCHOS_NA && __WATCH_OS_VERSION_MIN_REQUIRED < watchos))
854
855# define QT_MACOS_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(macos, ios) \
856 QT_DARWIN_PLATFORM_SDK_EQUAL_OR_ABOVE(macos, ios, __TVOS_NA, __WATCHOS_NA)
857# define QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(macos) \
858 QT_DARWIN_PLATFORM_SDK_EQUAL_OR_ABOVE(macos, __IPHONE_NA, __TVOS_NA, __WATCHOS_NA)
859# define QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(ios) \
860 QT_DARWIN_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_NA, ios, __TVOS_NA, __WATCHOS_NA)
861# define QT_TVOS_PLATFORM_SDK_EQUAL_OR_ABOVE(tvos) \
862 QT_DARWIN_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_NA, __IPHONE_NA, tvos, __WATCHOS_NA)
863# define QT_WATCHOS_PLATFORM_SDK_EQUAL_OR_ABOVE(watchos) \
864 QT_DARWIN_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_NA, __IPHONE_NA, __TVOS_NA, watchos)
865
866# define QT_MACOS_IOS_DEPLOYMENT_TARGET_BELOW(macos, ios) \
867 QT_DARWIN_DEPLOYMENT_TARGET_BELOW(macos, ios, __TVOS_NA, __WATCHOS_NA)
868# define QT_MACOS_DEPLOYMENT_TARGET_BELOW(macos) \
869 QT_DARWIN_DEPLOYMENT_TARGET_BELOW(macos, __IPHONE_NA, __TVOS_NA, __WATCHOS_NA)
870# define QT_IOS_DEPLOYMENT_TARGET_BELOW(ios) \
871 QT_DARWIN_DEPLOYMENT_TARGET_BELOW(__MAC_NA, ios, __TVOS_NA, __WATCHOS_NA)
872# define QT_TVOS_DEPLOYMENT_TARGET_BELOW(tvos) \
873 QT_DARWIN_DEPLOYMENT_TARGET_BELOW(__MAC_NA, __IPHONE_NA, tvos, __WATCHOS_NA)
874# define QT_WATCHOS_DEPLOYMENT_TARGET_BELOW(watchos) \
875 QT_DARWIN_DEPLOYMENT_TARGET_BELOW(__MAC_NA, __IPHONE_NA, __TVOS_NA, watchos)
876
877// Compatibility synonyms, do not use
878# define QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(osx, ios) QT_MACOS_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(osx, ios)
879# define QT_MAC_DEPLOYMENT_TARGET_BELOW(osx, ios) QT_MACOS_IOS_DEPLOYMENT_TARGET_BELOW(osx, ios)
880# define QT_OSX_PLATFORM_SDK_EQUAL_OR_ABOVE(osx) QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(osx)
881# define QT_OSX_DEPLOYMENT_TARGET_BELOW(osx) QT_MACOS_DEPLOYMENT_TARGET_BELOW(osx)
882
883// Implemented in qcore_mac_objc.mm
884class Q_CORE_EXPORT QMacAutoReleasePool
885{
886public:
887 QMacAutoReleasePool();
888 ~QMacAutoReleasePool();
889private:
890 Q_DISABLE_COPY(QMacAutoReleasePool)
891 void *pool;
892};
893
894#else
895
896#define QT_DARWIN_PLATFORM_SDK_EQUAL_OR_ABOVE(macos, ios, tvos, watchos) (0)
897#define QT_MACOS_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(macos, ios) (0)
898#define QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(macos) (0)
899#define QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(ios) (0)
900#define QT_TVOS_PLATFORM_SDK_EQUAL_OR_ABOVE(tvos) (0)
901#define QT_WATCHOS_PLATFORM_SDK_EQUAL_OR_ABOVE(watchos) (0)
902
903#define QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(osx, ios) (0)
904#define QT_OSX_PLATFORM_SDK_EQUAL_OR_ABOVE(osx) (0)
905
906#endif // Q_OS_DARWIN
907
908/*
909 Data stream functions are provided by many classes (defined in qdatastream.h)
910*/
911
912class QDataStream;
913
914inline void qt_noop(void) {}
915
916/* These wrap try/catch so we can switch off exceptions later.
917
918 Beware - do not use more than one QT_CATCH per QT_TRY, and do not use
919 the exception instance in the catch block.
920 If you can't live with those constraints, don't use these macros.
921 Use the QT_NO_EXCEPTIONS macro to protect your code instead.
922*/
923
924#if !defined(QT_NO_EXCEPTIONS)
925# if !defined(Q_MOC_RUN)
926# if (defined(Q_CC_CLANG) && !defined(Q_CC_INTEL) && !__has_feature(cxx_exceptions)) || \
927 (defined(Q_CC_GNU) && !defined(__EXCEPTIONS))
928# define QT_NO_EXCEPTIONS
929# endif
930# elif defined(QT_BOOTSTRAPPED)
931# define QT_NO_EXCEPTIONS
932# endif
933#endif
934
935Q_NORETURN Q_DECL_COLD_FUNCTION Q_CORE_EXPORT void qTerminate() noexcept;
936#ifdef QT_NO_EXCEPTIONS
937# define QT_TRY if (true)
938# define QT_CATCH(A) else
939# define QT_THROW(A) qt_noop()
940# define QT_RETHROW qt_noop()
941# define QT_TERMINATE_ON_EXCEPTION(expr) do { expr; } while (false)
942#else
943# define QT_TRY try
944# define QT_CATCH(A) catch (A)
945# define QT_THROW(A) throw A
946# define QT_RETHROW throw
947# ifdef Q_COMPILER_NOEXCEPT
948# define QT_TERMINATE_ON_EXCEPTION(expr) do { expr; } while (false)
949# else
950# define QT_TERMINATE_ON_EXCEPTION(expr) do { try { expr; } catch (...) { qTerminate(); } } while (false)
951# endif
952#endif
953
954Q_CORE_EXPORT Q_DECL_CONST_FUNCTION bool qSharedBuild() noexcept;
955
956#ifndef Q_OUTOFLINE_TEMPLATE
957# define Q_OUTOFLINE_TEMPLATE
958#endif
959#ifndef Q_INLINE_TEMPLATE
960# define Q_INLINE_TEMPLATE inline
961#endif
962
963/*
964 Debugging and error handling
965*/
966
967#if !defined(QT_NO_DEBUG) && !defined(QT_DEBUG)
968# define QT_DEBUG
969#endif
970
971// QtPrivate::asString defined in qstring.h
972#ifndef qPrintable
973# define qPrintable(string) QtPrivate::asString(string).toLocal8Bit().constData()
974#endif
975
976#ifndef qUtf8Printable
977# define qUtf8Printable(string) QtPrivate::asString(string).toUtf8().constData()
978#endif
979
980/*
981 Wrap QString::utf16() with enough casts to allow passing it
982 to QString::asprintf("%ls") without warnings.
983*/
984#ifndef qUtf16Printable
985# define qUtf16Printable(string) \
986 static_cast<const wchar_t*>(static_cast<const void*>(QString(string).utf16()))
987#endif
988
989class QString;
990Q_DECL_COLD_FUNCTION
991Q_CORE_EXPORT QString qt_error_string(int errorCode = -1);
992
993#ifndef Q_CC_MSVC
994Q_NORETURN
995#endif
996Q_DECL_COLD_FUNCTION
997Q_CORE_EXPORT void qt_assert(const char *assertion, const char *file, int line) noexcept;
998
999#if !defined(Q_ASSERT)
1000# if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS)
1001# define Q_ASSERT(cond) static_cast<void>(false && (cond))
1002# else
1003# define Q_ASSERT(cond) ((cond) ? static_cast<void>(0) : qt_assert(#cond, __FILE__, __LINE__))
1004# endif
1005#endif
1006
1007#ifndef Q_CC_MSVC
1008Q_NORETURN
1009#endif
1010Q_DECL_COLD_FUNCTION
1011Q_CORE_EXPORT void qt_assert_x(const char *where, const char *what, const char *file, int line) noexcept;
1012
1013#if !defined(Q_ASSERT_X)
1014# if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS)
1015# define Q_ASSERT_X(cond, where, what) static_cast<void>(false && (cond))
1016# else
1017# define Q_ASSERT_X(cond, where, what) ((cond) ? static_cast<void>(0) : qt_assert_x(where, what, __FILE__, __LINE__))
1018# endif
1019#endif
1020
1021Q_NORETURN Q_CORE_EXPORT void qt_check_pointer(const char *, int) noexcept;
1022Q_NORETURN Q_DECL_COLD_FUNCTION
1023Q_CORE_EXPORT void qBadAlloc();
1024
1025#ifdef QT_NO_EXCEPTIONS
1026# if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS)
1027# define Q_CHECK_PTR(p) qt_noop()
1028# else
1029# define Q_CHECK_PTR(p) do {if (!(p)) qt_check_pointer(__FILE__,__LINE__);} while (false)
1030# endif
1031#else
1032# define Q_CHECK_PTR(p) do { if (!(p)) qBadAlloc(); } while (false)
1033#endif
1034
1035template <typename T>
1036inline T *q_check_ptr(T *p) { Q_CHECK_PTR(p); return p; }
1037
1038typedef void (*QFunctionPointer)();
1039
1040#if !defined(Q_UNIMPLEMENTED)
1041# define Q_UNIMPLEMENTED() qWarning("Unimplemented code.")
1042#endif
1043
1044[[nodiscard]] constexpr bool qFuzzyCompare(double p1, double p2)
1045{
1046 return (qAbs(p1 - p2) * 1000000000000. <= qMin(qAbs(p1), qAbs(p2)));
1047}
1048
1049[[nodiscard]] constexpr bool qFuzzyCompare(float p1, float p2)
1050{
1051 return (qAbs(p1 - p2) * 100000.f <= qMin(qAbs(p1), qAbs(p2)));
1052}
1053
1054[[nodiscard]] constexpr bool qFuzzyIsNull(double d)
1055{
1056 return qAbs(d) <= 0.000000000001;
1057}
1058
1059[[nodiscard]] constexpr bool qFuzzyIsNull(float f)
1060{
1061 return qAbs(f) <= 0.00001f;
1062}
1063
1064QT_WARNING_PUSH
1065QT_WARNING_DISABLE_FLOAT_COMPARE
1066
1067[[nodiscard]] constexpr bool qIsNull(double d) noexcept
1068{
1069 return d == 0.0;
1070}
1071
1072[[nodiscard]] constexpr bool qIsNull(float f) noexcept
1073{
1074 return f == 0.0f;
1075}
1076
1077QT_WARNING_POP
1078
1079/*
1080 Compilers which follow outdated template instantiation rules
1081 require a class to have a comparison operator to exist when
1082 a QList of this type is instantiated. It's not actually
1083 used in the list, though. Hence the dummy implementation.
1084 Just in case other code relies on it we better trigger a warning
1085 mandating a real implementation.
1086*/
1087
1088#ifdef Q_FULL_TEMPLATE_INSTANTIATION
1089# define Q_DUMMY_COMPARISON_OPERATOR(C) \
1090 bool operator==(const C&) const { \
1091 qWarning(#C"::operator==(const "#C"&) was called"); \
1092 return false; \
1093 }
1094#else
1095
1096# define Q_DUMMY_COMPARISON_OPERATOR(C)
1097#endif
1098
1099QT_WARNING_PUSH
1100// warning: noexcept-expression evaluates to 'false' because of a call to 'void swap(..., ...)'
1101QT_WARNING_DISABLE_GCC("-Wnoexcept")
1102
1103namespace QtPrivate
1104{
1105namespace SwapExceptionTester { // insulate users from the "using std::swap" below
1106 using std::swap; // import std::swap
1107 template <typename T>
1108 void checkSwap(T &t)
1109 noexcept(noexcept(swap(t, t)));
1110 // declared, but not implemented (only to be used in unevaluated contexts (noexcept operator))
1111}
1112} // namespace QtPrivate
1113
1114// Documented in ../tools/qalgorithm.qdoc
1115template <typename T>
1116constexpr void qSwap(T &value1, T &value2)
1117 noexcept(noexcept(QtPrivate::SwapExceptionTester::checkSwap(value1)))
1118{
1119 using std::swap;
1120 swap(value1, value2);
1121}
1122
1123QT_WARNING_POP
1124
1125Q_CORE_EXPORT void *qMallocAligned(size_t size, size_t alignment) Q_ALLOC_SIZE(1);
1126Q_CORE_EXPORT void *qReallocAligned(void *ptr, size_t size, size_t oldsize, size_t alignment) Q_ALLOC_SIZE(2);
1127Q_CORE_EXPORT void qFreeAligned(void *ptr);
1128
1129
1130/*
1131 Avoid some particularly useless warnings from some stupid compilers.
1132 To get ALL C++ compiler warnings, define QT_CC_WARNINGS or comment out
1133 the line "#define QT_NO_WARNINGS".
1134*/
1135#if !defined(QT_CC_WARNINGS)
1136# define QT_NO_WARNINGS
1137#endif
1138#if defined(QT_NO_WARNINGS)
1139# if defined(Q_CC_MSVC)
1140QT_WARNING_DISABLE_MSVC(4251) /* class 'type' needs to have dll-interface to be used by clients of class 'type2' */
1141QT_WARNING_DISABLE_MSVC(4244) /* conversion from 'type1' to 'type2', possible loss of data */
1142QT_WARNING_DISABLE_MSVC(4275) /* non - DLL-interface classkey 'identifier' used as base for DLL-interface classkey 'identifier' */
1143QT_WARNING_DISABLE_MSVC(4514) /* unreferenced inline function has been removed */
1144QT_WARNING_DISABLE_MSVC(4800) /* 'type' : forcing value to bool 'true' or 'false' (performance warning) */
1145QT_WARNING_DISABLE_MSVC(4097) /* typedef-name 'identifier1' used as synonym for class-name 'identifier2' */
1146QT_WARNING_DISABLE_MSVC(4706) /* assignment within conditional expression */
1147QT_WARNING_DISABLE_MSVC(4355) /* 'this' : used in base member initializer list */
1148QT_WARNING_DISABLE_MSVC(4710) /* function not inlined */
1149QT_WARNING_DISABLE_MSVC(4530) /* C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc */
1150# elif defined(Q_CC_BOR)
1151# pragma option -w-inl
1152# pragma option -w-aus
1153# pragma warn -inl
1154# pragma warn -pia
1155# pragma warn -ccc
1156# pragma warn -rch
1157# pragma warn -sig
1158# endif
1159#endif
1160
1161// this adds const to non-const objects (like std::as_const)
1162template <typename T>
1163constexpr typename std::add_const<T>::type &qAsConst(T &t) noexcept { return t; }
1164// prevent rvalue arguments:
1165template <typename T>
1166void qAsConst(const T &&) = delete;
1167
1168// like std::exchange
1169template <typename T, typename U = T>
1170constexpr T qExchange(T &t, U &&newValue)
1171{
1172 T old = std::move(t);
1173 t = std::forward<U>(newValue);
1174 return old;
1175}
1176
1177// like std::to_underlying
1178template <typename Enum>
1179constexpr std::underlying_type_t<Enum> qToUnderlying(Enum e) noexcept
1180{
1181 return static_cast<std::underlying_type_t<Enum>>(e);
1182}
1183
1184#ifdef __cpp_conditional_explicit
1185#define Q_IMPLICIT explicit(false)
1186#else
1187#define Q_IMPLICIT
1188#endif
1189
1190#ifndef QT_NO_FOREACH
1191
1192namespace QtPrivate {
1193
1194template <typename T>
1195class QForeachContainer {
1196 Q_DISABLE_COPY(QForeachContainer)
1197public:
1198 QForeachContainer(const T &t) : c(t), i(qAsConst(c).begin()), e(qAsConst(c).end()) {}
1199 QForeachContainer(T &&t) : c(std::move(t)), i(qAsConst(c).begin()), e(qAsConst(c).end()) {}
1200
1201 QForeachContainer(QForeachContainer &&other)
1202 : c(std::move(other.c)),
1203 i(qAsConst(c).begin()),
1204 e(qAsConst(c).end()),
1205 control(std::move(other.control))
1206 {
1207 }
1208
1209 QForeachContainer &operator=(QForeachContainer &&other)
1210 {
1211 c = std::move(other.c);
1212 i = qAsConst(c).begin();
1213 e = qAsConst(c).end();
1214 control = std::move(other.control);
1215 return *this;
1216 }
1217
1218 T c;
1219 typename T::const_iterator i, e;
1220 int control = 1;
1221};
1222
1223// Containers that have a detach function are considered shared, and are OK in a foreach loop
1224template <typename T, typename = decltype(std::declval<T>().detach())>
1225inline void warnIfContainerIsNotShared(int) {}
1226
1227#if QT_DEPRECATED_SINCE(6, 0)
1228// Other containers will copy themselves if used in foreach, this use is deprecated
1229template <typename T>
1230QT_DEPRECATED_VERSION_X_6_0("Do not use foreach/Q_FOREACH with containers which are not implicitly shared. "
1231 "Prefer using a range-based for loop with these containers: `for (const auto &it : container)`, "
1232 "keeping in mind that range-based for doesn't copy the container as Q_FOREACH does")
1233inline void warnIfContainerIsNotShared(...) {}
1234#endif
1235
1236template<typename T>
1237QForeachContainer<typename std::decay<T>::type> qMakeForeachContainer(T &&t)
1238{
1239 warnIfContainerIsNotShared<typename std::decay<T>::type>(0);
1240 return QForeachContainer<typename std::decay<T>::type>(std::forward<T>(t));
1241}
1242
1243}
1244
1245// Use C++17 if statement with initializer. User's code ends up in a else so
1246// scoping of different ifs is not broken
1247#define Q_FOREACH_IMPL(variable, name, container) \
1248 for (auto name = QtPrivate::qMakeForeachContainer(container); name.i != name.e; ++name.i) \
1249 if (variable = *name.i; false) {} else
1250
1251#define Q_FOREACH_JOIN(A, B) Q_FOREACH_JOIN_IMPL(A, B)
1252#define Q_FOREACH_JOIN_IMPL(A, B) A ## B
1253
1254#define Q_FOREACH(variable, container) \
1255 Q_FOREACH_IMPL(variable, Q_FOREACH_JOIN(_container_, __LINE__), container)
1256#endif // QT_NO_FOREACH
1257
1258#define Q_FOREVER for(;;)
1259#ifndef QT_NO_KEYWORDS
1260# ifndef QT_NO_FOREACH
1261# ifndef foreach
1262# define foreach Q_FOREACH
1263# endif
1264# endif // QT_NO_FOREACH
1265# ifndef forever
1266# define forever Q_FOREVER
1267# endif
1268#endif
1269
1270template <typename T> inline T *qGetPtrHelper(T *ptr) noexcept { return ptr; }
1271template <typename Ptr> inline auto qGetPtrHelper(Ptr &ptr) noexcept -> decltype(ptr.get())
1272{ static_assert(noexcept(ptr.get()), "Smart d pointers for Q_DECLARE_PRIVATE must have noexcept get()"); return ptr.get(); }
1273
1274// The body must be a statement:
1275#define Q_CAST_IGNORE_ALIGN(body) QT_WARNING_PUSH QT_WARNING_DISABLE_GCC("-Wcast-align") body QT_WARNING_POP
1276#define Q_DECLARE_PRIVATE(Class) \
1277 inline Class##Private* d_func() noexcept \
1278 { Q_CAST_IGNORE_ALIGN(return reinterpret_cast<Class##Private *>(qGetPtrHelper(d_ptr));) } \
1279 inline const Class##Private* d_func() const noexcept \
1280 { Q_CAST_IGNORE_ALIGN(return reinterpret_cast<const Class##Private *>(qGetPtrHelper(d_ptr));) } \
1281 friend class Class##Private;
1282
1283#define Q_DECLARE_PRIVATE_D(Dptr, Class) \
1284 inline Class##Private* d_func() noexcept \
1285 { Q_CAST_IGNORE_ALIGN(return reinterpret_cast<Class##Private *>(qGetPtrHelper(Dptr));) } \
1286 inline const Class##Private* d_func() const noexcept \
1287 { Q_CAST_IGNORE_ALIGN(return reinterpret_cast<const Class##Private *>(qGetPtrHelper(Dptr));) } \
1288 friend class Class##Private;
1289
1290#define Q_DECLARE_PUBLIC(Class) \
1291 inline Class* q_func() noexcept { return static_cast<Class *>(q_ptr); } \
1292 inline const Class* q_func() const noexcept { return static_cast<const Class *>(q_ptr); } \
1293 friend class Class;
1294
1295#define Q_D(Class) Class##Private * const d = d_func()
1296#define Q_Q(Class) Class * const q = q_func()
1297
1298#define QT_TR_NOOP(x) x
1299#define QT_TR_NOOP_UTF8(x) x
1300#define QT_TRANSLATE_NOOP(scope, x) x
1301#define QT_TRANSLATE_NOOP_UTF8(scope, x) x
1302#define QT_TRANSLATE_NOOP3(scope, x, comment) {x, comment}
1303#define QT_TRANSLATE_NOOP3_UTF8(scope, x, comment) {x, comment}
1304
1305#ifndef QT_NO_TRANSLATION
1306
1307#define QT_TR_N_NOOP(x) x
1308#define QT_TRANSLATE_N_NOOP(scope, x) x
1309#define QT_TRANSLATE_N_NOOP3(scope, x, comment) {x, comment}
1310
1311// Defined in qcoreapplication.cpp
1312// The better name qTrId() is reserved for an upcoming function which would
1313// return a much more powerful QStringFormatter instead of a QString.
1314Q_CORE_EXPORT QString qtTrId(const char *id, int n = -1);
1315
1316#define QT_TRID_NOOP(id) id
1317
1318#endif // QT_NO_TRANSLATION
1319
1320
1321#ifdef Q_QDOC
1322// Just for documentation generation
1323template<typename T>
1324auto qOverload(T functionPointer);
1325template<typename T>
1326auto qConstOverload(T memberFunctionPointer);
1327template<typename T>
1328auto qNonConstOverload(T memberFunctionPointer);
1329#else
1330template <typename... Args>
1331struct QNonConstOverload
1332{
1333 template <typename R, typename T>
1334 constexpr auto operator()(R (T::*ptr)(Args...)) const noexcept -> decltype(ptr)
1335 { return ptr; }
1336
1337 template <typename R, typename T>
1338 static constexpr auto of(R (T::*ptr)(Args...)) noexcept -> decltype(ptr)
1339 { return ptr; }
1340};
1341
1342template <typename... Args>
1343struct QConstOverload
1344{
1345 template <typename R, typename T>
1346 constexpr auto operator()(R (T::*ptr)(Args...) const) const noexcept -> decltype(ptr)
1347 { return ptr; }
1348
1349 template <typename R, typename T>
1350 static constexpr auto of(R (T::*ptr)(Args...) const) noexcept -> decltype(ptr)
1351 { return ptr; }
1352};
1353
1354template <typename... Args>
1355struct QOverload : QConstOverload<Args...>, QNonConstOverload<Args...>
1356{
1357 using QConstOverload<Args...>::of;
1358 using QConstOverload<Args...>::operator();
1359 using QNonConstOverload<Args...>::of;
1360 using QNonConstOverload<Args...>::operator();
1361
1362 template <typename R>
1363 constexpr auto operator()(R (*ptr)(Args...)) const noexcept -> decltype(ptr)
1364 { return ptr; }
1365
1366 template <typename R>
1367 static constexpr auto of(R (*ptr)(Args...)) noexcept -> decltype(ptr)
1368 { return ptr; }
1369};
1370
1371template <typename... Args> constexpr inline QOverload<Args...> qOverload = {};
1372template <typename... Args> constexpr inline QConstOverload<Args...> qConstOverload = {};
1373template <typename... Args> constexpr inline QNonConstOverload<Args...> qNonConstOverload = {};
1374#endif
1375
1376
1377class QByteArray;
1378Q_CORE_EXPORT QByteArray qgetenv(const char *varName);
1379// need it as two functions because QString is only forward-declared here
1380Q_CORE_EXPORT QString qEnvironmentVariable(const char *varName);
1381Q_CORE_EXPORT QString qEnvironmentVariable(const char *varName, const QString &defaultValue);
1382Q_CORE_EXPORT bool qputenv(const char *varName, const QByteArray& value);
1383Q_CORE_EXPORT bool qunsetenv(const char *varName);
1384
1385Q_CORE_EXPORT bool qEnvironmentVariableIsEmpty(const char *varName) noexcept;
1386Q_CORE_EXPORT bool qEnvironmentVariableIsSet(const char *varName) noexcept;
1387Q_CORE_EXPORT int qEnvironmentVariableIntValue(const char *varName, bool *ok=nullptr) noexcept;
1388
1389inline int qIntCast(double f) { return int(f); }
1390inline int qIntCast(float f) { return int(f); }
1391
1392#define QT_MODULE(x)
1393
1394#if !defined(QT_BOOTSTRAPPED) && defined(QT_REDUCE_RELOCATIONS) && defined(__ELF__) && \
1395 (!defined(__PIC__) || (defined(__PIE__) && defined(Q_CC_GNU) && Q_CC_GNU >= 500))
1396# error "You must build your code with position independent code if Qt was built with -reduce-relocations. "\
1397 "Compile your code with -fPIC (and not with -fPIE)."
1398#endif
1399
1400#define QT_VA_ARGS_CHOOSE(_1, _2, _3, _4, _5, _6, _7, _8, _9, N, ...) N
1401#define QT_VA_ARGS_EXPAND(...) __VA_ARGS__ // Needed for MSVC
1402#define QT_VA_ARGS_COUNT(...) QT_VA_ARGS_EXPAND(QT_VA_ARGS_CHOOSE(__VA_ARGS__, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0))
1403#define QT_OVERLOADED_MACRO_EXPAND(MACRO, ARGC) MACRO##_##ARGC
1404#define QT_OVERLOADED_MACRO_IMP(MACRO, ARGC) QT_OVERLOADED_MACRO_EXPAND(MACRO, ARGC)
1405#define QT_OVERLOADED_MACRO(MACRO, ...) QT_VA_ARGS_EXPAND(QT_OVERLOADED_MACRO_IMP(MACRO, QT_VA_ARGS_COUNT(__VA_ARGS__))(__VA_ARGS__))
1406
1407// This macro can be used to calculate member offsets for types with a non standard layout.
1408// It uses the fact that offsetof() is allowed to support those types since C++17 as an optional
1409// feature. All our compilers do support this, but some issue a warning, so we wrap the offsetof()
1410// call in a macro that disables the compiler warning.
1411#define Q_OFFSETOF(Class, member) \
1412 []() -> size_t { \
1413 QT_WARNING_PUSH QT_WARNING_DISABLE_INVALID_OFFSETOF \
1414 return offsetof(Class, member); \
1415 QT_WARNING_POP \
1416 }()
1417
1418QT_END_NAMESPACE
1419
1420// We need to keep QTypeInfo, QSysInfo, QFlags, qDebug & family in qglobal.h for compatibility with Qt 4.
1421// Be careful when changing the order of these files.
1422#include <QtCore/qtypeinfo.h>
1423#include <QtCore/qsysinfo.h>
1424#include <QtCore/qlogging.h>
1425
1426#include <QtCore/qflags.h>
1427
1428#include <QtCore/qatomic.h>
1429#include <QtCore/qglobalstatic.h>
1430#include <QtCore/qnumeric.h>
1431#include <QtCore/qversiontagging.h>
1432
1433#endif /* __cplusplus */
1434#endif /* !__ASSEMBLER__ */
1435
1436#endif /* QGLOBAL_H */
1437

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