qt 6.6.0 clean

This commit is contained in:
kleuter
2023-11-01 22:23:55 +01:00
parent 7b5ada15e7
commit 5d8194efa7
1449 changed files with 134276 additions and 31391 deletions

View File

@ -21,3 +21,4 @@ add_subdirectory(qglobalstatic)
add_subdirectory(qhooks)
add_subdirectory(qoperatingsystemversion)
add_subdirectory(qxp)
add_subdirectory(q20)

View File

@ -0,0 +1 @@
add_subdirectory(memory)

View File

@ -0,0 +1,10 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
qt_internal_add_test(tst_q20_memory
EXCEPTIONS
SOURCES
tst_q20_memory.cpp
LIBRARIES
Qt::Core
)

View File

@ -0,0 +1,161 @@
// Copyright (C) 2020 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz <marc.mutz@kdab.com>
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <q20memory.h>
#include <QtCore/q20memory.h>
#include <QTest>
#include <QObject>
#include <QExplicitlySharedDataPointer>
#include <QSharedDataPointer>
struct Private : QSharedData {};
class tst_q20_memory : public QObject
{
Q_OBJECT
private Q_SLOTS:
void raw();
void smart();
void recursion();
void usesPointerTraits();
void prefersPointerTraits();
private Q_SLOTS:
void to_address_broken_const_propagation_QExplicitlySharedDataPointer()
{ to_address_broken_const_propagation<QExplicitlySharedDataPointer<Private>>(); }
void to_address_broken_const_propagation_QSharedDataPointer()
{ to_address_broken_const_propagation<QSharedDataPointer<Private>>(); }
void to_address_broken_const_propagation_shared_ptr()
{ to_address_broken_const_propagation<std::shared_ptr<Private>>(); }
void to_address_broken_const_propagation_unique_ptr()
{ to_address_broken_const_propagation<std::unique_ptr<Private>>(); }
private:
template <typename Pointer>
void to_address_broken_const_propagation();
};
void tst_q20_memory::raw()
{
auto i = 0;
auto p = &i;
QVERIFY(q20::to_address(p) == &i);
}
template <typename T>
class MinimalPtr {
public:
using element_type = T;
explicit MinimalPtr(T *d) : d(d) {}
T *operator->() const noexcept { return d; }
private:
T *d;
};
void tst_q20_memory::smart()
{
int i;
MinimalPtr ptr(&i);
QCOMPARE_EQ(q20::to_address(ptr), &i);
}
template <typename T>
class RecursivePtr {
public:
using element_type = T;
explicit RecursivePtr(T *d) : d(d) {}
MinimalPtr<T> operator->() const noexcept { return d; }
private:
MinimalPtr<T> d;
};
void tst_q20_memory::recursion()
{
int i;
RecursivePtr ptr(&i);
QCOMPARE_EQ(q20::to_address(ptr), &i);
}
template <typename T>
class NoDerefOperatorPtr {
public:
using element_type = T;
explicit NoDerefOperatorPtr(T *d) : d(d) {}
T *get() const noexcept { return d; }
private:
T *d;
};
namespace std {
template <typename T>
struct pointer_traits<NoDerefOperatorPtr<T>>
{
static T *to_address(const NoDerefOperatorPtr<T> &ptr) noexcept { return ptr.get(); }
};
} // namespace std
void tst_q20_memory::usesPointerTraits()
{
int i;
NoDerefOperatorPtr ptr(&i);
QCOMPARE_EQ(q20::to_address(ptr), &i);
}
template <typename T>
class PrefersPointerTraitsPtr
{
public:
using element_type = T;
explicit PrefersPointerTraitsPtr(T *d) : d(d) {}
T *operator->() const noexcept { return nullptr; }
T *get() const noexcept { return d; }
private:
T *d;
};
namespace std {
template <typename T>
struct pointer_traits<PrefersPointerTraitsPtr<T>>
{
static T *to_address(const PrefersPointerTraitsPtr<T> &p) noexcept { return p.get(); }
};
} // namespace std
void tst_q20_memory::prefersPointerTraits()
{
int i;
PrefersPointerTraitsPtr ptr(&i);
QCOMPARE_EQ(q20::to_address(ptr), &i);
}
template <typename Pointer>
void tst_q20_memory::to_address_broken_const_propagation()
{
Pointer p(nullptr);
QCOMPARE_EQ(q20::to_address(p), nullptr);
p = Pointer{new Private()};
QCOMPARE_EQ(q20::to_address(p), p.operator->());
static_assert(std::is_same_v<decltype(q20::to_address(p)),
decltype(std::as_const(p).operator->())>);
}
QTEST_GUILESS_MAIN(tst_q20_memory)
#include "tst_q20_memory.moc"

View File

@ -301,7 +301,7 @@ Q_DECLARE_FLAGS( MyStrictNoOpFlags, MyStrictNoOpEnum )
static_assert( !QTypeInfo<MyStrictFlags>::isComplex );
static_assert( QTypeInfo<MyStrictFlags>::isRelocatable );
static_assert( !QTypeInfo<MyStrictFlags>::isPointer );
static_assert( !std::is_pointer_v<MyStrictFlags> );
void tst_QFlags::classEnum()
{
@ -475,7 +475,7 @@ Q_DECLARE_OPERATORS_FOR_FLAGS( MyFlags )
static_assert( !QTypeInfo<MyFlags>::isComplex );
static_assert( QTypeInfo<MyFlags>::isRelocatable );
static_assert( !QTypeInfo<MyFlags>::isPointer );
static_assert( !std::is_pointer_v<MyFlags> );
QTEST_MAIN(tst_QFlags)
#include "tst_qflags.moc"

View File

@ -3,6 +3,7 @@
#include <QtCore/qglobal.h>
#include <QtCore/qtversion.h>
#include <QtCore/qtypes.h>
#ifdef Q_COMPILER_THREAD_LOCAL
# include <threads.h>
@ -44,8 +45,20 @@ void tst_GlobalTypes()
qintptr qip;
quintptr qup;
Q_UNUSED(qs); Q_UNUSED(qp); Q_UNUSED(qip); Q_UNUSED(qup);
#ifdef QT_SUPPORTS_INT128
qint128 s128;
quint128 u128;
Q_UNUSED(s128); Q_UNUSED(u128);
#endif /* QT_SUPPORTS_INT128 */
}
#if QT_SUPPORTS_INT128
qint128 tst_qint128_min() { return Q_INT128_MIN + 0; }
qint128 tst_qint128_max() { return 0 + Q_INT128_MAX; }
quint128 tst_quint128_max() { return Q_UINT128_MAX - 1 + 1; }
#endif
/* Qt version */
int tst_QtVersion()
{

View File

@ -10,8 +10,49 @@
#include <QString>
#include <QtVersion>
#include <array>
#include <cmath>
QT_BEGIN_NAMESPACE
namespace QTest {
#ifdef QT_SUPPORTS_INT128
namespace detail {
char *i128ToStringHelper(std::array<char, 64> &buffer, quint128 n)
{
auto dst = buffer.data() + buffer.size();
*--dst = '\0'; // NUL-terminate
if (n == 0) {
*--dst = '0'; // and done
} else {
while (n != 0) {
*--dst = "0123456789"[n % 10];
n /= 10;
}
}
return dst;
}
}
template <>
char *toString(const qint128 &i)
{
if (i == std::numeric_limits<qint128>::min()) // -i is not representable, hardcode:
return qstrdup("-170141183460469231731687303715884105728");
std::array<char, 64> buffer;
auto dst = detail::i128ToStringHelper(buffer, i < 0 ? -i : i);
if (i < 0)
*--dst = '-';
return qstrdup(dst);
}
template <>
char *toString(const quint128 &i)
{
std::array<char, 64> buffer;
return qstrdup(detail::i128ToStringHelper(buffer, i));
}
#endif // QT_SUPPORTS_INT128
} // namespace QTest
QT_END_NAMESPACE
class tst_QGlobal: public QObject
{
Q_OBJECT
@ -28,6 +69,7 @@ private slots:
void qCoreAppStartupFunction();
void qCoreAppStartupFunctionRestart();
void integerForSize();
void int128Literals();
void buildAbiEndianness();
void testqOverload();
void testqMinMax();
@ -37,12 +79,19 @@ private slots:
void qRoundDoubles();
void PRImacros();
void testqToUnderlying();
void nodiscardConstructor();
};
extern "C" { // functions in qglobal.c
void tst_GlobalTypes();
int tst_QtVersion();
const char *tst_qVersion();
#if QT_SUPPORTS_INT128
qint128 tst_qint128_min();
qint128 tst_qint128_max();
quint128 tst_quint128_max();
#endif
}
void tst_QGlobal::cMode()
@ -421,11 +470,166 @@ void tst_QGlobal::integerForSize()
static_assert(sizeof(QIntegerForSize<2>::Signed) == 2);
static_assert(sizeof(QIntegerForSize<4>::Signed) == 4);
static_assert(sizeof(QIntegerForSize<8>::Signed) == 8);
#ifdef QT_SUPPORTS_INT128
static_assert(sizeof(QIntegerForSize<16>::Signed) == 16);
#endif
static_assert(sizeof(QIntegerForSize<1>::Unsigned) == 1);
static_assert(sizeof(QIntegerForSize<2>::Unsigned) == 2);
static_assert(sizeof(QIntegerForSize<4>::Unsigned) == 4);
static_assert(sizeof(QIntegerForSize<8>::Unsigned) == 8);
#ifdef QT_SUPPORTS_INT128
static_assert(sizeof(QIntegerForSize<16>::Unsigned) == 16);
#endif
}
void tst_QGlobal::int128Literals()
{
#ifdef QT_SUPPORTS_INT128
#define COMPARE_EQ(lhs, rhs, Expected128) do { \
constexpr auto lhs_ = lhs; \
static_assert(std::is_same_v<std::remove_cv_t<decltype(lhs_)>, Expected128>); \
QCOMPARE_EQ(lhs_, rhs); \
} while (0)
COMPARE_EQ(Q_INT128_MIN, std::numeric_limits<qint128>::min(), qint128);
COMPARE_EQ(Q_INT128_MAX, std::numeric_limits<qint128>::max(), qint128);
COMPARE_EQ(Q_UINT128_MAX, std::numeric_limits<quint128>::max(), quint128);
QCOMPARE_EQ(tst_qint128_min(), Q_INT128_MIN);
QCOMPARE_EQ(tst_qint128_max(), Q_INT128_MAX);
QCOMPARE_EQ(tst_quint128_max(), Q_UINT128_MAX);
{
#define CHECK_S(x) COMPARE_EQ(Q_INT128_C(x), Q_INT64_C(x), qint128)
#define CHECK_U(x) COMPARE_EQ(Q_UINT128_C(x), Q_UINT64_C(x), quint128);
#define CHECK(x) do { CHECK_S(x); CHECK_U(x); } while (0)
// basics:
CHECK(0);
CHECK(1);
CHECK_S(-1);
QCOMPARE_EQ(Q_INT64_C(9223372036854775807), std::numeric_limits<qint64>::max());
CHECK(9223372036854775807); // LLONG_MAX
// Q_INT64_C(-9223372036854775808) gives -Wimplicitly-unsigned-literal on GCC, so use numeric_limits:
{
constexpr auto i = Q_INT128_C(-9223372036854775808); // LLONG_MIN
static_assert(std::is_same_v<decltype(i), const qint128>);
QCOMPARE_EQ(i, std::numeric_limits<qint64>::min());
}
// actual 128-bit numbers
{
constexpr auto i = Q_INT128_C( 9223372036854775808); // LLONG_MAX + 1
constexpr auto u = Q_UINT128_C(9223372036854775808); // LLONG_MAX + 1
static_assert(std::is_same_v<decltype(i), const qint128>);
static_assert(std::is_same_v<decltype(u), const quint128>);
QCOMPARE_EQ(i, qint128{ std::numeric_limits<qint64>::max()} + 1);
QCOMPARE_EQ(u, quint128{std::numeric_limits<qint64>::max()} + 1);
}
{
constexpr auto i = Q_INT128_C(-9223372036854775809); // LLONG_MIN - 1
static_assert(std::is_same_v<decltype(i), const qint128>);
QCOMPARE_EQ(i, qint128{std::numeric_limits<qint64>::min()} - 1);
}
{
constexpr auto i = Q_INT128_C( 18446744073709551616); // ULLONG_MAX + 1
constexpr auto u = Q_UINT128_C(18446744073709551616);
constexpr auto expected = qint128{1} << 64;
static_assert(std::is_same_v<decltype(i), const qint128>);
static_assert(std::is_same_v<decltype(expected), const qint128>);
static_assert(std::is_same_v<decltype(u), const quint128>);
QCOMPARE_EQ(i, expected);
QCOMPARE_EQ(u, quint128{expected});
}
{
// compilers don't let one write signed _MIN literals, so use MIN + 1:
// Q_INT128_C(-170141183460469231731687303715884105728) gives
// ERROR: ~~~ outside range of representable values of type qint128
// This is because the unary minus is technically speaking not part of
// the literal, but called on the result of the literal.
constexpr auto i = Q_INT128_C(-170141183460469231731687303715884105727); // 128-bit MIN + 1
static_assert(std::is_same_v<decltype(i), const qint128>);
QCOMPARE_EQ(i, std::numeric_limits<qint128>::min() + 1);
}
{
constexpr auto i = Q_INT128_C( 170141183460469231731687303715884105727); // MAX
constexpr auto u = Q_UINT128_C(340282366920938463463374607431768211455); // UMAX
static_assert(std::is_same_v<decltype(i), const qint128>);
static_assert(std::is_same_v<decltype(u), const quint128>);
QCOMPARE_EQ(i, std::numeric_limits<qint128>::max());
QCOMPARE_EQ(u, std::numeric_limits<quint128>::max());
QCOMPARE_EQ(u, Q_UINT128_C(-1));
}
// binary literals:
CHECK(0b0);
CHECK(0b1);
CHECK_S(-0b1);
CHECK(0b01);
CHECK(0b10);
CHECK(0b1'1); // with digit separator
CHECK(0b0111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111);
//bytes |---1---| |---2---| |---3---| |---4---| |---5---| |---6---| |---7---| |---8---|
{
// bytes: |---1---| |---2---| |---3---| |---4---| |---5---| |---6---| |---7---| |---8---| |---9---| |--10---| |--11---| |--12---| |--13---| |--14---| |--15---| |--16---|
constexpr auto i = Q_INT128_C( 0b0111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111);
constexpr auto u = Q_UINT128_C(0b1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111'1111);
static_assert(std::is_same_v<decltype(i), const qint128>);
static_assert(std::is_same_v<decltype(u), const quint128>);
QCOMPARE_EQ(i, std::numeric_limits<qint128>::max());
QCOMPARE_EQ(u, std::numeric_limits<quint128>::max());
QCOMPARE_EQ(u, Q_UINT128_C(-0b1));
}
// octal literals:
CHECK(00);
CHECK(01);
CHECK(02);
CHECK(03);
CHECK(04);
CHECK(05);
CHECK(06);
CHECK(07);
CHECK_S(-01);
CHECK(010);
CHECK_S(-01'0); // with digit separator
CHECK(07'7777'7777'7777'7777'7777); // LLONG_MAX
{
// bits: 120| 108| 96| 84| 72| 60| 48| 36| 24| 12| 0|
constexpr auto i = Q_INT128_C( 0177'7777'7777'7777'7777'7777'7777'7777'7777'7777'7777);
constexpr auto u = Q_UINT128_C(0377'7777'7777'7777'7777'7777'7777'7777'7777'7777'7777);
static_assert(std::is_same_v<decltype(i), const qint128>);
static_assert(std::is_same_v<decltype(u), const quint128>);
QCOMPARE_EQ(i, std::numeric_limits<qint128>::max());
QCOMPARE_EQ(u, std::numeric_limits<quint128>::max());
QCOMPARE_EQ(u, Q_UINT128_C(-01));
}
// hex literals:
CHECK(0x0);
CHECK(0x1);
CHECK(0x9);
CHECK(0xA);
CHECK(0xB);
CHECK(0xC);
CHECK(0xD);
CHECK(0xE);
CHECK(0x0F);
CHECK(0x10);
CHECK_S(-0x1);
CHECK_S(-0x1'0); // with digit separator
CHECK(0x7FFF'FFFF'FFFF'FFFF);
{
constexpr auto i = Q_INT128_C( 0x7FFF'FFFF'FFFF'FFFF'FFFF'FFFF'FFFF'FFFF);
constexpr auto u = Q_UINT128_C(0xFFFF'FFFF'FFFF'FFFF'FFFF'FFFF'FFFF'FFFF);
static_assert(std::is_same_v<decltype(i), const qint128>);
static_assert(std::is_same_v<decltype(u), const quint128>);
QCOMPARE_EQ(i, std::numeric_limits<qint128>::max());
QCOMPARE_EQ(u, std::numeric_limits<quint128>::max());
QCOMPARE_EQ(Q_UINT128_C(-1), u);
}
#undef CHECK
}
#undef COMPARE_EQ
#else
QSKIP("This test requires 128-bit integer support enabled in the compiler.");
#endif
}
typedef QPair<const char *, const char *> stringpair;
@ -691,5 +895,25 @@ void tst_QGlobal::testqToUnderlying()
QCOMPARE(qToUnderlying(EE2), 456UL);
}
void tst_QGlobal::nodiscardConstructor()
{
// Syntax-only test, just to make sure that Q_NODISCARD_CTOR compiles
// on all platforms.
// Other code is just to silence all various compiler warnings about
// unused private members or methods.
class Test {
public:
Q_NODISCARD_CTOR explicit Test(int val) : m_val(val) {}
int get() const { return m_val; }
private:
int m_val;
};
Test t{42};
QCOMPARE(t.get(), 42);
}
QTEST_APPLESS_MAIN(tst_QGlobal)
#include "tst_qglobal.moc"