From caf57f0ca3d67ec6d79193a252590b6d7e4e4493 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 7 Aug 2024 09:22:12 +0200 Subject: [PATCH] tst_QGlobal: add a build of this test in strict mode This is in preparation of adding some static assertions here that we need to have evaluated in both "normal" and "strict" mode, namely and support for qint128. But this change is more general, so making it a separate change. Turns out we already have (non-static) assertions here about support for qint128. These force us to define precisely when GCC/libstdc++ has gained support for __int128_t: the timestamp of the __GLIBCXX__ macro is the Daily Bump immediately preceding the gcc commit that fixed (gcc/8eb9a45e87bdb81cb44948c651edee846c622a0f). Let's hope no-one is running the prerelease version of GCC 10.3 from that particular day, otherwise these might become XPASSes. But just not testing is also wrong; we want to be informed about True Positives and Negatives here. Task-number: QTBUG-119901 Pick-to: 6.7 6.5 Change-Id: I6f9be047f846fff74133c466c5bed40d0039d60f Reviewed-by: Alexandru Croitor Reviewed-by: Thiago Macieira (cherry picked from commit e7c54248987d474cff9f49cad502822eb9dcb114) Reviewed-by: Qt Cherry-pick Bot --- .../corelib/global/qglobal/CMakeLists.txt | 12 ++++++++++ .../corelib/global/qglobal/tst_qglobal.cpp | 22 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/tests/auto/corelib/global/qglobal/CMakeLists.txt b/tests/auto/corelib/global/qglobal/CMakeLists.txt index 5a0877663b..527e218aba 100644 --- a/tests/auto/corelib/global/qglobal/CMakeLists.txt +++ b/tests/auto/corelib/global/qglobal/CMakeLists.txt @@ -19,5 +19,17 @@ qt_internal_add_test(tst_qglobal tst_qglobal.cpp # undef QT_NO_FOREACH ) +# check stuff (esp. qtypes.h) works in -ansi mode +qt_internal_add_test(tst_qglobal_strict + SOURCES + qglobal.c + tst_qglobal.cpp + DEFINES + tst_QGlobal=tst_QGlobal_strict + NO_PCH_SOURCES + tst_qglobal.cpp # undef QT_NO_FOREACH +) +_qt_internal_apply_strict_cpp(tst_qglobal_strict) + ## Scopes: ##################################################################### diff --git a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp index 954eab6a43..e67f991fae 100644 --- a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp +++ b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp @@ -544,13 +544,25 @@ void tst_QGlobal::integerForSize() void tst_QGlobal::int128Literals() { #ifdef QT_SUPPORTS_INT128 +# if defined(__GLIBCXX__) && defined(__STRICT_ANSI__) && \ + (_GLIBCXX_RELEASE < 10 || \ + _GLIBCXX_RELEASE == 10 && __GLIBCXX__ < 20201112L /*gcc commit 8eb9a45e87bdb81cb44948c651edee846c622a0f*/) + // -ansi/-std=c++NN instead of gnu++NN + // breaks on libstdc++ <= 10.2; fixed in 10.3+ +# define QTBUG_119901_MAYBE_FAIL QEXPECT_FAIL("", "QTBUG-119901", Continue) +# else +# define QTBUG_119901_MAYBE_FAIL do {} while (false) +# endif #define COMPARE_EQ(lhs, rhs, Expected128) do { \ constexpr auto lhs_ = lhs; \ static_assert(std::is_same_v, Expected128>); \ QCOMPARE_EQ(lhs_, rhs); \ } while (0) + QTBUG_119901_MAYBE_FAIL; COMPARE_EQ(Q_INT128_MIN, std::numeric_limits::min(), qint128); + QTBUG_119901_MAYBE_FAIL; COMPARE_EQ(Q_INT128_MAX, std::numeric_limits::max(), qint128); + QTBUG_119901_MAYBE_FAIL; COMPARE_EQ(Q_UINT128_MAX, std::numeric_limits::max(), quint128); QCOMPARE_EQ(tst_qint128_min(), Q_INT128_MIN); QCOMPARE_EQ(tst_qint128_max(), Q_INT128_MAX); @@ -603,6 +615,7 @@ void tst_QGlobal::int128Literals() // 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); + QTBUG_119901_MAYBE_FAIL; QCOMPARE_EQ(i, std::numeric_limits::min() + 1); } { @@ -610,7 +623,9 @@ void tst_QGlobal::int128Literals() constexpr auto u = Q_UINT128_C(340282366920938463463374607431768211455); // UMAX static_assert(std::is_same_v); static_assert(std::is_same_v); + QTBUG_119901_MAYBE_FAIL; QCOMPARE_EQ(i, std::numeric_limits::max()); + QTBUG_119901_MAYBE_FAIL; QCOMPARE_EQ(u, std::numeric_limits::max()); QCOMPARE_EQ(u, Q_UINT128_C(-1)); } @@ -630,7 +645,9 @@ void tst_QGlobal::int128Literals() 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); static_assert(std::is_same_v); + QTBUG_119901_MAYBE_FAIL; QCOMPARE_EQ(i, std::numeric_limits::max()); + QTBUG_119901_MAYBE_FAIL; QCOMPARE_EQ(u, std::numeric_limits::max()); QCOMPARE_EQ(u, Q_UINT128_C(-0b1)); } @@ -654,7 +671,9 @@ void tst_QGlobal::int128Literals() constexpr auto u = Q_UINT128_C(0377'7777'7777'7777'7777'7777'7777'7777'7777'7777'7777); static_assert(std::is_same_v); static_assert(std::is_same_v); + QTBUG_119901_MAYBE_FAIL; QCOMPARE_EQ(i, std::numeric_limits::max()); + QTBUG_119901_MAYBE_FAIL; QCOMPARE_EQ(u, std::numeric_limits::max()); QCOMPARE_EQ(u, Q_UINT128_C(-01)); } @@ -678,12 +697,15 @@ void tst_QGlobal::int128Literals() constexpr auto u = Q_UINT128_C(0xFFFF'FFFF'FFFF'FFFF'FFFF'FFFF'FFFF'FFFF); static_assert(std::is_same_v); static_assert(std::is_same_v); + QTBUG_119901_MAYBE_FAIL; QCOMPARE_EQ(i, std::numeric_limits::max()); + QTBUG_119901_MAYBE_FAIL; QCOMPARE_EQ(u, std::numeric_limits::max()); QCOMPARE_EQ(Q_UINT128_C(-1), u); } #undef CHECK } +#undef QTBUG_119901_MAYBE_FAIL #undef COMPARE_EQ #else QSKIP("This test requires 128-bit integer support enabled in the compiler.");