diff options
Diffstat (limited to 'tests')
9 files changed, 32 insertions, 166 deletions
diff --git a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp index b33dec8a61..047130d5ea 100644 --- a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp +++ b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp @@ -49,7 +49,6 @@ private slots: void qConstructorFunction(); void qCoreAppStartupFunction(); void qCoreAppStartupFunctionRestart(); - void qAlignOf(); void integerForSize(); void qprintable(); void qprintable_data(); @@ -434,106 +433,6 @@ template <class T> struct AlignmentInStruct { T dummy; }; typedef int (*fun) (); typedef int (Empty::*memFun) (); -#define TEST_AlignOf(type, alignment) \ - do { \ - TEST_AlignOf_impl(type, alignment); \ - \ - TEST_AlignOf_impl(type &, alignment); \ - TEST_AlignOf_RValueRef(type &&, alignment); \ - \ - TEST_AlignOf_impl(type [5], alignment); \ - TEST_AlignOf_impl(type (&) [5], alignment); \ - \ - TEST_AlignOf_impl(AlignmentInStruct<type>, alignment); \ - \ - /* Some internal sanity validation, just for fun */ \ - TEST_AlignOf_impl(AlignmentInStruct<type [5]>, alignment); \ - TEST_AlignOf_impl(AlignmentInStruct<type &>, Q_ALIGNOF(void *)); \ - TEST_AlignOf_impl(AlignmentInStruct<type (&) [5]>, \ - Q_ALIGNOF(void *)); \ - TEST_AlignOf_RValueRef(AlignmentInStruct<type &&>, \ - Q_ALIGNOF(void *)); \ - } while (false) \ - /**/ - -#define TEST_AlignOf_RValueRef(type, alignment) \ - TEST_AlignOf_impl(type, alignment) - -#define TEST_AlignOf_impl(type, alignment) \ - do { \ - QCOMPARE(Q_ALIGNOF(type), size_t(alignment)); \ - /* Compare to native operator for compilers that support it, - otherwise... erm... check consistency! :-) */ \ - QCOMPARE(alignof(type), Q_ALIGNOF(type)); \ - } while (false) - /**/ - -void tst_QGlobal::qAlignOf() -{ - // Built-in types, except 64-bit integers and double - TEST_AlignOf(char, 1); - TEST_AlignOf(signed char, 1); - TEST_AlignOf(unsigned char, 1); - TEST_AlignOf(qint8, 1); - TEST_AlignOf(quint8, 1); - TEST_AlignOf(qint16, 2); - TEST_AlignOf(quint16, 2); - TEST_AlignOf(qint32, 4); - TEST_AlignOf(quint32, 4); - TEST_AlignOf(void *, sizeof(void *)); - - // Depends on platform and compiler, disabling test for now - // TEST_AlignOf(long double, 16); - - // Empty struct - TEST_AlignOf(Empty, 1); - - // Function pointers - TEST_AlignOf(fun, Q_ALIGNOF(void *)); - TEST_AlignOf(memFun, Q_ALIGNOF(void *)); - - - // 64-bit integers and double - TEST_AlignOf_impl(qint64, 8); - TEST_AlignOf_impl(quint64, 8); - TEST_AlignOf_impl(double, 8); - - TEST_AlignOf_impl(qint64 &, 8); - TEST_AlignOf_impl(quint64 &, 8); - TEST_AlignOf_impl(double &, 8); - - TEST_AlignOf_RValueRef(qint64 &&, 8); - TEST_AlignOf_RValueRef(quint64 &&, 8); - TEST_AlignOf_RValueRef(double &&, 8); - - // 32-bit x86 ABI idiosyncrasies -#if defined(Q_PROCESSOR_X86_32) && !defined(Q_OS_WIN) - TEST_AlignOf_impl(AlignmentInStruct<qint64>, 4); -#else - TEST_AlignOf_impl(AlignmentInStruct<qint64>, 8); -#endif - - TEST_AlignOf_impl(AlignmentInStruct<quint64>, Q_ALIGNOF(AlignmentInStruct<qint64>)); - TEST_AlignOf_impl(AlignmentInStruct<double>, Q_ALIGNOF(AlignmentInStruct<qint64>)); - - // 32-bit x86 ABI, Clang disagrees with gcc -#if !defined(Q_PROCESSOR_X86_32) || !defined(Q_CC_CLANG) || defined(Q_OS_ANDROID) - TEST_AlignOf_impl(qint64 [5], Q_ALIGNOF(qint64)); -#else - TEST_AlignOf_impl(qint64 [5], Q_ALIGNOF(AlignmentInStruct<qint64>)); -#endif - - TEST_AlignOf_impl(qint64 (&) [5], Q_ALIGNOF(qint64 [5])); - TEST_AlignOf_impl(quint64 [5], Q_ALIGNOF(quint64 [5])); - TEST_AlignOf_impl(quint64 (&) [5], Q_ALIGNOF(quint64 [5])); - TEST_AlignOf_impl(double [5], Q_ALIGNOF(double [5])); - TEST_AlignOf_impl(double (&) [5], Q_ALIGNOF(double [5])); -} - -#undef TEST_AlignOf -#undef TEST_AlignOf_RValueRef -#undef TEST_AlignOf_impl - void tst_QGlobal::integerForSize() { // compile-only test: diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp index 12c29a6e13..2a4ee55fa8 100644 --- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp @@ -1024,9 +1024,9 @@ static void testConstructHelper() typedef typename MetaEnumToType<ID>::Type Type; QMetaType info(ID); int size = info.sizeOf(); - void *storage1 = qMallocAligned(size, Q_ALIGNOF(Type)); + void *storage1 = qMallocAligned(size, alignof(Type)); void *actual1 = QMetaType::construct(ID, storage1, /*copy=*/0); - void *storage2 = qMallocAligned(size, Q_ALIGNOF(Type)); + void *storage2 = qMallocAligned(size, alignof(Type)); void *actual2 = info.construct(storage2, /*copy=*/0); QCOMPARE(actual1, storage1); QCOMPARE(actual2, storage2); @@ -1178,9 +1178,9 @@ static void testConstructCopyHelper() QMetaType info(ID); int size = QMetaType::sizeOf(ID); QCOMPARE(info.sizeOf(), size); - void *storage1 = qMallocAligned(size, Q_ALIGNOF(Type)); + void *storage1 = qMallocAligned(size, alignof(Type)); void *actual1 = QMetaType::construct(ID, storage1, expected); - void *storage2 = qMallocAligned(size, Q_ALIGNOF(Type)); + void *storage2 = qMallocAligned(size, alignof(Type)); void *actual2 = info.construct(storage2, expected); QCOMPARE(actual1, storage1); QCOMPARE(actual2, storage2); diff --git a/tests/auto/corelib/thread/qatomicint/tst_qatomicint.cpp b/tests/auto/corelib/thread/qatomicint/tst_qatomicint.cpp index bef491d5f0..22ee7d17b7 100644 --- a/tests/auto/corelib/thread/qatomicint/tst_qatomicint.cpp +++ b/tests/auto/corelib/thread/qatomicint/tst_qatomicint.cpp @@ -237,28 +237,23 @@ template <typename T> struct TypeInStruct { T type; }; void tst_QAtomicInt::alignment() { -#ifdef Q_ALIGNOF - // this will cause a build error if the alignment isn't the same - char dummy1[Q_ALIGNOF(QBasicAtomicInt) == Q_ALIGNOF(TypeInStruct<int>) ? 1 : -1]; - char dummy2[Q_ALIGNOF(QAtomicInt) == Q_ALIGNOF(TypeInStruct<int>) ? 1 : -1]; - (void)dummy1; (void)dummy2; + Q_STATIC_ASSERT(alignof(QBasicAtomicInt) == alignof(TypeInStruct<int>)); + Q_STATIC_ASSERT(alignof(QBasicAtomicInt) == alignof(TypeInStruct<int>)); #ifdef Q_ATOMIC_INT32_IS_SUPPORTED - QCOMPARE(Q_ALIGNOF(QBasicAtomicInteger<int>), Q_ALIGNOF(TypeInStruct<int>)); + QCOMPARE(alignof(QBasicAtomicInteger<int>), alignof(TypeInStruct<int>)); #endif #ifdef Q_ATOMIC_INT16_IS_SUPPORTED - QCOMPARE(Q_ALIGNOF(QBasicAtomicInteger<short>), Q_ALIGNOF(TypeInStruct<short>)); + QCOMPARE(alignof(QBasicAtomicInteger<short>), alignof(TypeInStruct<short>)); #endif #ifdef Q_ATOMIC_INT8_IS_SUPPORTED - QCOMPARE(Q_ALIGNOF(QBasicAtomicInteger<char>), Q_ALIGNOF(TypeInStruct<char>)); + QCOMPARE(alignof(QBasicAtomicInteger<char>), alignof(TypeInStruct<char>)); #endif #ifdef Q_ATOMIC_INT64_IS_SUPPORTED - QCOMPARE(Q_ALIGNOF(QBasicAtomicInteger<qlonglong>), Q_ALIGNOF(TypeInStruct<qlonglong>)); -#endif - + QCOMPARE(alignof(QBasicAtomicInteger<qlonglong>), alignof(TypeInStruct<qlonglong>)); #endif } diff --git a/tests/auto/corelib/thread/qatomicpointer/tst_qatomicpointer.cpp b/tests/auto/corelib/thread/qatomicpointer/tst_qatomicpointer.cpp index a699cf6202..9e12e7ccce 100644 --- a/tests/auto/corelib/thread/qatomicpointer/tst_qatomicpointer.cpp +++ b/tests/auto/corelib/thread/qatomicpointer/tst_qatomicpointer.cpp @@ -108,11 +108,7 @@ void tst_QAtomicPointer::warningFree() void tst_QAtomicPointer::alignment() { -#ifdef Q_ALIGNOF - // this will cause a build error if the alignment isn't the same - char dummy[Q_ALIGNOF(QBasicAtomicPointer<void>) == Q_ALIGNOF(void*) ? 1 : -1]; - (void)dummy; -#endif + Q_STATIC_ASSERT(alignof(QBasicAtomicPointer<void>) == alignof(void*)); } void tst_QAtomicPointer::constructor() diff --git a/tests/auto/corelib/tools/collections/tst_collections.cpp b/tests/auto/corelib/tools/collections/tst_collections.cpp index e79a4dba29..8aca12f9d6 100644 --- a/tests/auto/corelib/tools/collections/tst_collections.cpp +++ b/tests/auto/corelib/tools/collections/tst_collections.cpp @@ -3214,7 +3214,7 @@ void tst_Collections::forwardDeclared() { typedef QSet<T1> C; C *x = 0; /* C::iterator i; */ C::const_iterator j; Q_UNUSED(x) } } -#if defined(Q_ALIGNOF) && defined(Q_DECL_ALIGN) +#if defined(Q_DECL_ALIGN) class Q_DECL_ALIGN(4) Aligned4 { @@ -3228,7 +3228,7 @@ public: inline bool operator<(const Aligned4 &other) const { return i < other.i; } friend inline int qHash(const Aligned4 &a) { return qHash(a.i); } }; -Q_STATIC_ASSERT(Q_ALIGNOF(Aligned4) % 4 == 0); +Q_STATIC_ASSERT(alignof(Aligned4) % 4 == 0); #if defined(Q_PROCESSOR_ARM) # if defined(Q_COMPILER_ALIGNAS) && defined(__BIGGEST_ALIGNMENT__) @@ -3254,7 +3254,7 @@ public: inline bool operator<(const AlignedBiggest &other) const { return i < other.i; } friend inline int qHash(const AlignedBiggest &a) { return qHash(a.i); } }; -Q_STATIC_ASSERT(Q_ALIGNOF(AlignedBiggest) % BIGGEST_ALIGNMENT_TO_TEST == 0); +Q_STATIC_ASSERT(alignof(AlignedBiggest) % BIGGEST_ALIGNMENT_TO_TEST == 0); template<typename C> void testVectorAlignment() diff --git a/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp b/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp index 25e2f21d03..12752e4d07 100644 --- a/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp +++ b/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp @@ -160,7 +160,7 @@ void tst_QArrayData::referenceCounting() void tst_QArrayData::sharedNullEmpty() { QArrayData *null = const_cast<QArrayData *>(QArrayData::shared_null); - QArrayData *empty = QArrayData::allocate(1, Q_ALIGNOF(QArrayData), 0); + QArrayData *empty = QArrayData::allocate(1, alignof(QArrayData), 0); QVERIFY(null->ref.isStatic()); QVERIFY(null->ref.isShared()); @@ -657,16 +657,16 @@ void tst_QArrayData::allocate_data() size_t objectSize; size_t alignment; } types[] = { - { "char", sizeof(char), Q_ALIGNOF(char) }, - { "short", sizeof(short), Q_ALIGNOF(short) }, - { "void *", sizeof(void *), Q_ALIGNOF(void *) } + { "char", sizeof(char), alignof(char) }, + { "short", sizeof(short), alignof(short) }, + { "void *", sizeof(void *), alignof(void *) } }; - QArrayData *shared_empty = QArrayData::allocate(0, Q_ALIGNOF(QArrayData), 0); + QArrayData *shared_empty = QArrayData::allocate(0, alignof(QArrayData), 0); QVERIFY(shared_empty); #if !defined(QT_NO_UNSHARABLE_CONTAINERS) - QArrayData *unsharable_empty = QArrayData::allocate(0, Q_ALIGNOF(QArrayData), 0, QArrayData::Unsharable); + QArrayData *unsharable_empty = QArrayData::allocate(0, alignof(QArrayData), 0, QArrayData::Unsharable); QVERIFY(unsharable_empty); #endif @@ -709,7 +709,7 @@ void tst_QArrayData::allocate() // Minimum alignment that can be requested is that of QArrayData. // Typically, this alignment is sizeof(void *) and ensured by malloc. - size_t minAlignment = qMax(alignment, Q_ALIGNOF(QArrayData)); + size_t minAlignment = qMax(alignment, alignof(QArrayData)); // Shared Empty QCOMPARE(QArrayData::allocate(objectSize, minAlignment, 0, @@ -749,11 +749,11 @@ void tst_QArrayData::reallocate() // Maximum alignment that can be requested is that of QArrayData, // otherwise, we can't use reallocate(). - Q_ASSERT(alignment <= Q_ALIGNOF(QArrayData)); + Q_ASSERT(alignment <= alignof(QArrayData)); // Minimum alignment that can be requested is that of QArrayData. // Typically, this alignment is sizeof(void *) and ensured by malloc. - size_t minAlignment = qMax(alignment, Q_ALIGNOF(QArrayData)); + size_t minAlignment = qMax(alignment, alignof(QArrayData)); int capacity = 10; Deallocator keeper(objectSize, minAlignment); @@ -808,7 +808,7 @@ void tst_QArrayData::alignment() // Minimum alignment that can be requested is that of QArrayData. // Typically, this alignment is sizeof(void *) and ensured by malloc. - size_t minAlignment = qMax(alignment, Q_ALIGNOF(QArrayData)); + size_t minAlignment = qMax(alignment, alignof(QArrayData)); Deallocator keeper(sizeof(Unaligned), minAlignment); keeper.headers.reserve(100); @@ -826,7 +826,7 @@ void tst_QArrayData::alignment() // allocated together QVERIFY(data->offset >= qptrdiff(sizeof(QArrayData))); QVERIFY(data->offset <= qptrdiff(sizeof(QArrayData) - + minAlignment - Q_ALIGNOF(QArrayData))); + + minAlignment - alignof(QArrayData))); // Data is aligned QCOMPARE(quintptr(quintptr(data->data()) % alignment), quintptr(0u)); @@ -886,7 +886,7 @@ void tst_QArrayData::typedData() { Deallocator keeper(sizeof(char), - Q_ALIGNOF(QTypedArrayData<char>::AlignmentDummy)); + alignof(QTypedArrayData<char>::AlignmentDummy)); QArrayData *array = QTypedArrayData<char>::allocate(10); keeper.headers.append(array); @@ -906,7 +906,7 @@ void tst_QArrayData::typedData() { Deallocator keeper(sizeof(short), - Q_ALIGNOF(QTypedArrayData<short>::AlignmentDummy)); + alignof(QTypedArrayData<short>::AlignmentDummy)); QArrayData *array = QTypedArrayData<short>::allocate(10); keeper.headers.append(array); @@ -926,7 +926,7 @@ void tst_QArrayData::typedData() { Deallocator keeper(sizeof(double), - Q_ALIGNOF(QTypedArrayData<double>::AlignmentDummy)); + alignof(QTypedArrayData<double>::AlignmentDummy)); QArrayData *array = QTypedArrayData<double>::allocate(10); keeper.headers.append(array); diff --git a/tests/auto/gui/kernel/qguimetatype/tst_qguimetatype.cpp b/tests/auto/gui/kernel/qguimetatype/tst_qguimetatype.cpp index 1d0484a05d..2645bb111e 100644 --- a/tests/auto/gui/kernel/qguimetatype/tst_qguimetatype.cpp +++ b/tests/auto/gui/kernel/qguimetatype/tst_qguimetatype.cpp @@ -316,30 +316,10 @@ void tst_QGuiMetaType::sizeOf() QCOMPARE(QMetaType::sizeOf(type), size); } -#ifndef Q_ALIGNOF -template<uint N> -struct RoundToNextHighestPowerOfTwo -{ -private: - enum { V1 = N-1 }; - enum { V2 = V1 | (V1 >> 1) }; - enum { V3 = V2 | (V2 >> 2) }; - enum { V4 = V3 | (V3 >> 4) }; - enum { V5 = V4 | (V4 >> 8) }; - enum { V6 = V5 | (V5 >> 16) }; -public: - enum { Value = V6 + 1 }; -}; -#endif - template<class T> struct TypeAlignment { -#ifdef Q_ALIGNOF - enum { Value = Q_ALIGNOF(T) }; -#else - enum { Value = RoundToNextHighestPowerOfTwo<sizeof(T)>::Value }; -#endif + enum { Value = alignof(T) }; }; void tst_QGuiMetaType::flags_data() diff --git a/tests/auto/other/compiler/tst_compiler.cpp b/tests/auto/other/compiler/tst_compiler.cpp index de15f4c62d..78026665be 100644 --- a/tests/auto/other/compiler/tst_compiler.cpp +++ b/tests/auto/other/compiler/tst_compiler.cpp @@ -634,7 +634,7 @@ void tst_Compiler::cxx11_alignas() struct S { alignas(double) char c; }; - QCOMPARE(Q_ALIGNOF(S), Q_ALIGNOF(double)); + QCOMPARE(alignof(S), alignof(double)); #endif } @@ -1396,7 +1396,7 @@ void tst_Compiler::cxx11_unrestricted_unions() ~U() {} }; U u; - std::aligned_storage<sizeof(QString), Q_ALIGNOF(QString)> as; + std::aligned_storage<sizeof(QString), alignof(QString)> as; Q_UNUSED(u); Q_UNUSED(as); diff --git a/tests/benchmarks/corelib/tools/qvector/qrawvector.h b/tests/benchmarks/corelib/tools/qvector/qrawvector.h index 16a911c63a..73d8620f10 100644 --- a/tests/benchmarks/corelib/tools/qvector/qrawvector.h +++ b/tests/benchmarks/corelib/tools/qvector/qrawvector.h @@ -280,11 +280,7 @@ private: } static Q_DECL_CONSTEXPR int alignOfTypedData() { -#ifdef Q_ALIGNOF - return Q_ALIGNOF(AlignmentDummy); -#else - return sizeof(void *); -#endif + return alignof(AlignmentDummy); } public: |