From 3e1d03b1eaf6a5e842bed4ae4f9bb8cca05e5b31 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Thu, 11 Jun 2020 11:35:19 +0200 Subject: Port Q_STATIC_ASSERT(_X) to static_assert There is no reason for keep using our macro now that we have C++17. The macro itself is left in for the moment being, as well as its detection logic, because it's needed for C code (not everything supports C11 yet). A few more cleanups will arrive in the next few patches. Note that this is a mere search/replace; some places were using double braces to work around the presence of commas in a macro, no attempt has been done to fix those. tst_qglobal had just some minor changes to keep testing the macro. Change-Id: I1c1c397d9f3e63db3338842bf350c9069ea57639 Reviewed-by: Lars Knoll --- tests/auto/corelib/global/qflags/tst_qflags.cpp | 16 ++++++------- tests/auto/corelib/global/qglobal/qglobal.c | 6 +++++ tests/auto/corelib/global/qglobal/tst_qglobal.cpp | 26 ++++++++++------------ .../auto/corelib/global/qnumeric/tst_qnumeric.cpp | 4 ++-- .../qrandomgenerator/tst_qrandomgenerator.cpp | 8 +++---- 5 files changed, 32 insertions(+), 28 deletions(-) (limited to 'tests/auto/corelib/global') diff --git a/tests/auto/corelib/global/qflags/tst_qflags.cpp b/tests/auto/corelib/global/qflags/tst_qflags.cpp index 4df448373d..7060fc8b31 100644 --- a/tests/auto/corelib/global/qflags/tst_qflags.cpp +++ b/tests/auto/corelib/global/qflags/tst_qflags.cpp @@ -135,10 +135,10 @@ void tst_QFlags::signedness() // underlying type is implementation-defined, we need to allow for // a different signedness, so we only check that the relative // signedness of the types matches: - Q_STATIC_ASSERT((std::is_unsigned::type>::value == + static_assert((std::is_unsigned::type>::value == std::is_unsigned::value)); - Q_STATIC_ASSERT((std::is_signed::type>::value == + static_assert((std::is_signed::type>::value == std::is_signed::value)); } @@ -149,9 +149,9 @@ Q_DECLARE_OPERATORS_FOR_FLAGS( MyStrictFlags ) enum class MyStrictNoOpEnum { StrictZero, StrictOne, StrictTwo, StrictFour=4 }; Q_DECLARE_FLAGS( MyStrictNoOpFlags, MyStrictNoOpEnum ) -Q_STATIC_ASSERT( !QTypeInfo::isComplex ); -Q_STATIC_ASSERT( !QTypeInfo::isStatic ); -Q_STATIC_ASSERT( !QTypeInfo::isPointer ); +static_assert( !QTypeInfo::isComplex ); +static_assert( !QTypeInfo::isStatic ); +static_assert( !QTypeInfo::isPointer ); void tst_QFlags::classEnum() { @@ -319,9 +319,9 @@ enum MyEnum { Zero, One, Two, Four=4 }; Q_DECLARE_FLAGS( MyFlags, MyEnum ) Q_DECLARE_OPERATORS_FOR_FLAGS( MyFlags ) -Q_STATIC_ASSERT( !QTypeInfo::isComplex ); -Q_STATIC_ASSERT( !QTypeInfo::isStatic ); -Q_STATIC_ASSERT( !QTypeInfo::isPointer ); +static_assert( !QTypeInfo::isComplex ); +static_assert( !QTypeInfo::isStatic ); +static_assert( !QTypeInfo::isPointer ); QTEST_MAIN(tst_QFlags) #include "tst_qflags.moc" diff --git a/tests/auto/corelib/global/qglobal/qglobal.c b/tests/auto/corelib/global/qglobal/qglobal.c index 7a2266ae94..2f59119292 100644 --- a/tests/auto/corelib/global/qglobal/qglobal.c +++ b/tests/auto/corelib/global/qglobal/qglobal.c @@ -106,6 +106,12 @@ Q_STATIC_ASSERT(!0); Q_STATIC_ASSERT(!!true); Q_STATIC_ASSERT(!!1); +#ifdef __COUNTER__ +// if the compiler supports __COUNTER__, multiple +// Q_STATIC_ASSERT's on a single line should compile: +Q_STATIC_ASSERT(true); Q_STATIC_ASSERT_X(!false, ""); +#endif // __COUNTER__ + #ifdef Q_COMPILER_THREAD_LOCAL static thread_local int gt_var; void thread_local_test() diff --git a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp index cde4ea9633..7787c00218 100644 --- a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp +++ b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp @@ -345,6 +345,9 @@ struct MyTemplate void tst_QGlobal::qstaticassert() { + // Test multiple Q_STATIC_ASSERT on a single line + Q_STATIC_ASSERT(true); Q_STATIC_ASSERT_X(!false, ""); + // Force compilation of these classes MyTrue tmp1; MyExpresion tmp2; @@ -352,11 +355,6 @@ void tst_QGlobal::qstaticassert() Q_UNUSED(tmp1); Q_UNUSED(tmp2); Q_UNUSED(tmp3); -#ifdef __COUNTER__ - // if the compiler supports __COUNTER__, multiple - // Q_STATIC_ASSERT's on a single line should compile: - Q_STATIC_ASSERT(true); Q_STATIC_ASSERT_X(!false, ""); -#endif // __COUNTER__ QVERIFY(true); // if the test compiles it has passed. } @@ -433,15 +431,15 @@ typedef int (Empty::*memFun) (); void tst_QGlobal::integerForSize() { // compile-only test: - Q_STATIC_ASSERT(sizeof(QIntegerForSize<1>::Signed) == 1); - Q_STATIC_ASSERT(sizeof(QIntegerForSize<2>::Signed) == 2); - Q_STATIC_ASSERT(sizeof(QIntegerForSize<4>::Signed) == 4); - Q_STATIC_ASSERT(sizeof(QIntegerForSize<8>::Signed) == 8); - - Q_STATIC_ASSERT(sizeof(QIntegerForSize<1>::Unsigned) == 1); - Q_STATIC_ASSERT(sizeof(QIntegerForSize<2>::Unsigned) == 2); - Q_STATIC_ASSERT(sizeof(QIntegerForSize<4>::Unsigned) == 4); - Q_STATIC_ASSERT(sizeof(QIntegerForSize<8>::Unsigned) == 8); + static_assert(sizeof(QIntegerForSize<1>::Signed) == 1); + static_assert(sizeof(QIntegerForSize<2>::Signed) == 2); + static_assert(sizeof(QIntegerForSize<4>::Signed) == 4); + static_assert(sizeof(QIntegerForSize<8>::Signed) == 8); + + 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); } typedef QPair stringpair; diff --git a/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp b/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp index e1b8336955..da52e6e026 100644 --- a/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp +++ b/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp @@ -228,7 +228,7 @@ void tst_QNumeric::distinctNaNF() { template void tst_QNumeric::generalNaN_data() { - Q_STATIC_ASSERT(sizeof(F) == sizeof(Whole)); + static_assert(sizeof(F) == sizeof(Whole)); QTest::addColumn("whole"); // Every value with every bit of the exponent set is a NaN. // Sign and mantissa can be anything without interfering with that. @@ -251,7 +251,7 @@ void tst_QNumeric::generalNaN_data() template void tst_QNumeric::generalNaN() { - Q_STATIC_ASSERT(sizeof(F) == sizeof(Whole)); + static_assert(sizeof(F) == sizeof(Whole)); QFETCH(const Whole, whole); F nan; memcpy(&nan, &whole, sizeof(F)); diff --git a/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp b/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp index c3407bcc52..1c6e013adb 100644 --- a/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp +++ b/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp @@ -182,8 +182,8 @@ void tst_QRandomGenerator::basics() QRandomGenerator64 systemRng64 = *system64; systemRng64 = *system64; - Q_STATIC_ASSERT(std::is_same::value); - Q_STATIC_ASSERT(std::is_samegenerate()) COMMA quint64>::value); + static_assert(std::is_same::value); + static_assert(std::is_samegenerate()) COMMA quint64>::value); } void tst_QRandomGenerator::knownSequence() @@ -390,7 +390,7 @@ void tst_QRandomGenerator::quality() AcceptableThreshold = 4 * PerfectDistribution, FailureThreshold = 16 * PerfectDistribution }; - Q_STATIC_ASSERT(FailureThreshold > AcceptableThreshold); + static_assert(FailureThreshold > AcceptableThreshold); QFETCH(uint, control); if (control & RandomDataMask) @@ -609,7 +609,7 @@ void tst_QRandomGenerator::boundedQuality() AcceptableThreshold = 4 * PerfectDistribution, FailureThreshold = 16 * PerfectDistribution }; - Q_STATIC_ASSERT(FailureThreshold > AcceptableThreshold); + static_assert(FailureThreshold > AcceptableThreshold); QFETCH(uint, control); if (control & RandomDataMask) -- cgit v1.2.3