Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qtypes.cpp
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// Copyright (C) 2022 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 "qtypes.h"
6
7#include <QtCore/qcompilerdetection.h>
8#include <QtCore/qsystemdetection.h>
9#include <QtCore/qprocessordetection.h>
10
11#include <climits>
12#include <limits>
13#include <type_traits>
14
16
346// Statically check assumptions about the environment we're running
347// in. The idea here is to error or warn if otherwise implicit Qt
348// assumptions are not fulfilled on new hardware or compilers
349// (if this list becomes too long, consider factoring into a separate file)
350static_assert(UCHAR_MAX == 255, "Qt assumes that char is 8 bits");
351static_assert(sizeof(int) == 4, "Qt assumes that int is 32 bits");
352static_assert(QT_POINTER_SIZE == sizeof(void *), "QT_POINTER_SIZE defined incorrectly");
353static_assert(sizeof(float) == 4, "Qt assumes that float is 32 bits");
354static_assert(sizeof(char16_t) == 2, "Qt assumes that char16_t is 16 bits");
355static_assert(sizeof(char32_t) == 4, "Qt assumes that char32_t is 32 bits");
356#if defined(Q_OS_WIN)
357static_assert(sizeof(wchar_t) == sizeof(char16_t));
358#endif
359static_assert(std::numeric_limits<int>::radix == 2,
360 "Qt assumes binary integers");
361static_assert((std::numeric_limits<int>::max() + std::numeric_limits<int>::lowest()) == -1,
362 "Qt assumes two's complement integers");
363static_assert(sizeof(wchar_t) == sizeof(char32_t) || sizeof(wchar_t) == sizeof(char16_t),
364 "Qt assumes wchar_t is compatible with either char32_t or char16_t");
365
366// While we'd like to check for __STDC_IEC_559__, as per ISO/IEC 9899:2011
367// Annex F (C11, normative for C++11), there are a few corner cases regarding
368// denormals where GHS compiler is relying hardware behavior that is not IEC
369// 559 compliant. So split the check in several subchecks.
370
371// On GHS the compiler reports std::numeric_limits<float>::is_iec559 as false.
372// This is all right according to our needs.
373#if !defined(Q_CC_GHS)
374static_assert(std::numeric_limits<float>::is_iec559,
375 "Qt assumes IEEE 754 floating point");
376#endif
377
378// Technically, presence of NaN and infinities are implied from the above check,
379// but double checking our environment doesn't hurt...
380static_assert(std::numeric_limits<float>::has_infinity &&
381 std::numeric_limits<float>::has_quiet_NaN,
382 "Qt assumes IEEE 754 floating point");
383
384// is_iec559 checks for ISO/IEC/IEEE 60559:2011 (aka IEEE 754-2008) compliance,
385// but that allows for a non-binary radix. We need to recheck that.
386// Note how __STDC_IEC_559__ would instead check for IEC 60559:1989, aka
387// ANSI/IEEE 754−1985, which specifically implies binary floating point numbers.
388static_assert(std::numeric_limits<float>::radix == 2,
389 "Qt assumes binary IEEE 754 floating point");
390
391// not required by the definition of size_t, but we depend on this
392static_assert(sizeof(size_t) == sizeof(void *), "size_t and a pointer don't have the same size");
393static_assert(sizeof(size_t) == sizeof(qsizetype)); // implied by the definition
394static_assert((std::is_same<qsizetype, qptrdiff>::value));
395static_assert(std::is_same_v<std::size_t, size_t>);
396
397// Check that our own typedefs are not broken.
398static_assert(sizeof(qint8) == 1, "Internal error, qint8 is misdefined");
399static_assert(sizeof(qint16)== 2, "Internal error, qint16 is misdefined");
400static_assert(sizeof(qint32) == 4, "Internal error, qint32 is misdefined");
401static_assert(sizeof(qint64) == 8, "Internal error, qint64 is misdefined");
402
Combined button and popup list for selecting options.
#define QT_POINTER_SIZE
short qint16
Definition qtypes.h:42
int qint32
Definition qtypes.h:44
ptrdiff_t qsizetype
Definition qtypes.h:70
long long qint64
Definition qtypes.h:55
QT_BEGIN_NAMESPACE typedef signed char qint8
Definition qtypes.h:40