summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/global
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2020-06-11 11:35:19 +0200
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2020-06-19 19:38:23 +0200
commit3e1d03b1eaf6a5e842bed4ae4f9bb8cca05e5b31 (patch)
tree74dd3478dce3bc96121238300fc0bbc6ef97fc3e /tests/auto/corelib/global
parent5b686e208ffc68f9f660d36c468280d50a40e3ad (diff)
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 <lars.knoll@qt.io>
Diffstat (limited to 'tests/auto/corelib/global')
-rw-r--r--tests/auto/corelib/global/qflags/tst_qflags.cpp16
-rw-r--r--tests/auto/corelib/global/qglobal/qglobal.c6
-rw-r--r--tests/auto/corelib/global/qglobal/tst_qglobal.cpp26
-rw-r--r--tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp4
-rw-r--r--tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp8
5 files changed, 32 insertions, 28 deletions
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<typename std::underlying_type<Qt::MouseButton>::type>::value ==
+ static_assert((std::is_unsigned<typename std::underlying_type<Qt::MouseButton>::type>::value ==
std::is_unsigned<Qt::MouseButtons::Int>::value));
- Q_STATIC_ASSERT((std::is_signed<typename std::underlying_type<Qt::AlignmentFlag>::type>::value ==
+ static_assert((std::is_signed<typename std::underlying_type<Qt::AlignmentFlag>::type>::value ==
std::is_signed<Qt::Alignment::Int>::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<MyStrictFlags>::isComplex );
-Q_STATIC_ASSERT( !QTypeInfo<MyStrictFlags>::isStatic );
-Q_STATIC_ASSERT( !QTypeInfo<MyStrictFlags>::isPointer );
+static_assert( !QTypeInfo<MyStrictFlags>::isComplex );
+static_assert( !QTypeInfo<MyStrictFlags>::isStatic );
+static_assert( !QTypeInfo<MyStrictFlags>::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<MyFlags>::isComplex );
-Q_STATIC_ASSERT( !QTypeInfo<MyFlags>::isStatic );
-Q_STATIC_ASSERT( !QTypeInfo<MyFlags>::isPointer );
+static_assert( !QTypeInfo<MyFlags>::isComplex );
+static_assert( !QTypeInfo<MyFlags>::isStatic );
+static_assert( !QTypeInfo<MyFlags>::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<const char *, const char *> 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<typename F, typename Whole>
void tst_QNumeric::generalNaN_data()
{
- Q_STATIC_ASSERT(sizeof(F) == sizeof(Whole));
+ static_assert(sizeof(F) == sizeof(Whole));
QTest::addColumn<Whole>("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<typename F, typename Whole>
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<decltype(rng64.generate()) COMMA quint64>::value);
- Q_STATIC_ASSERT(std::is_same<decltype(system64->generate()) COMMA quint64>::value);
+ static_assert(std::is_same<decltype(rng64.generate()) COMMA quint64>::value);
+ static_assert(std::is_same<decltype(system64->generate()) 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)