Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
455// Statically check assumptions about the environment we're running
456// in. The idea here is to error or warn if otherwise implicit Qt
457// assumptions are not fulfilled on new hardware or compilers
458// (if this list becomes too long, consider factoring into a separate file)
459static_assert(UCHAR_MAX == 255, "Qt assumes that char is 8 bits");
460static_assert(sizeof(int) == 4, "Qt assumes that int is 32 bits");
461static_assert(QT_POINTER_SIZE == sizeof(void *), "QT_POINTER_SIZE defined incorrectly");
462static_assert(sizeof(float) == 4, "Qt assumes that float is 32 bits");
463static_assert(sizeof(char16_t) == 2, "Qt assumes that char16_t is 16 bits");
464static_assert(sizeof(char32_t) == 4, "Qt assumes that char32_t is 32 bits");
465#if defined(Q_OS_WIN)
466static_assert(sizeof(wchar_t) == sizeof(char16_t));
467#endif
468static_assert(std::numeric_limits<int>::radix == 2,
469 "Qt assumes binary integers");
470static_assert((std::numeric_limits<int>::max() + std::numeric_limits<int>::lowest()) == -1,
471 "Qt assumes two's complement integers");
472static_assert(sizeof(wchar_t) == sizeof(char32_t) || sizeof(wchar_t) == sizeof(char16_t),
473 "Qt assumes wchar_t is compatible with either char32_t or char16_t");
474
475// While we'd like to check for __STDC_IEC_559__, as per ISO/IEC 9899:2011
476// Annex F (C11, normative for C++11), there are a few corner cases regarding
477// denormals where GHS compiler is relying hardware behavior that is not IEC
478// 559 compliant. So split the check in several subchecks.
479
480// On GHS the compiler reports std::numeric_limits<float>::is_iec559 as false.
481// This is all right according to our needs.
482#if !defined(Q_CC_GHS)
483static_assert(std::numeric_limits<float>::is_iec559,
484 "Qt assumes IEEE 754 floating point");
485#endif
486
487// Technically, presence of NaN and infinities are implied from the above check,
488// but double checking our environment doesn't hurt...
489static_assert(std::numeric_limits<float>::has_infinity &&
490 std::numeric_limits<float>::has_quiet_NaN,
491 "Qt assumes IEEE 754 floating point");
492
493// is_iec559 checks for ISO/IEC/IEEE 60559:2011 (aka IEEE 754-2008) compliance,
494// but that allows for a non-binary radix. We need to recheck that.
495// Note how __STDC_IEC_559__ would instead check for IEC 60559:1989, aka
496// ANSI/IEEE 754−1985, which specifically implies binary floating point numbers.
497static_assert(std::numeric_limits<float>::radix == 2,
498 "Qt assumes binary IEEE 754 floating point");
499
500// not required by the definition of size_t, but we depend on this
501static_assert(sizeof(size_t) == sizeof(void *), "size_t and a pointer don't have the same size");
502static_assert(sizeof(size_t) == sizeof(qsizetype)); // implied by the definition
503static_assert((std::is_same<qsizetype, qptrdiff>::value));
504static_assert(std::is_same_v<std::size_t, size_t>);
505
506// Check that our own typedefs are not broken.
507static_assert(sizeof(qint8) == 1, "Internal error, qint8 is misdefined");
508static_assert(sizeof(qint16)== 2, "Internal error, qint16 is misdefined");
509static_assert(sizeof(qint32) == 4, "Internal error, qint32 is misdefined");
510static_assert(sizeof(qint64) == 8, "Internal error, qint64 is misdefined");
511#ifdef QT_SUPPORTS_INT128
512static_assert(sizeof(qint128) == 16, "Internal error, qint128 is misdefined");
513#endif
514
515#ifdef QT_SUPPORTS_INT128
516// Standard Library supports for 128-bit integers:
517// Implementation | Version | Note
518// ---------------------|---------|------
519// GNU libstdc++ | 11.1.0 |
520// LLVM libc++ | 3.5 | May change if compiler has __is_integral()
521// MS STL | none |
522
523# if defined(_LIBCPP_VERSION) || (defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE >= 11)
524static_assert(std::numeric_limits<quint128>::max() == Q_UINT128_MAX);
525# endif
526#endif
527
Combined button and popup list for selecting options.
#define QT_POINTER_SIZE
short qint16
Definition qtypes.h:47
int qint32
Definition qtypes.h:49
ptrdiff_t qsizetype
Definition qtypes.h:165
long long qint64
Definition qtypes.h:60
QT_BEGIN_NAMESPACE typedef signed char qint8
Definition qtypes.h:45