From ec2af0a9df0ac7bf9036f59a94ac3f3ef45c6740 Mon Sep 17 00:00:00 2001 From: Konrad Kujawa Date: Wed, 14 Sep 2022 09:49:00 +0200 Subject: [PATCH] Remove preprocessor conditionals for chrono include __has_include() is always true, because C++11 chrono include is required since 6.0. Pick-to: 6.4 6.3 6.2 Change-Id: I50cb92571bf4f1f86e2f3f2b5f486dd3c3f30f4a Reviewed-by: Thiago Macieira --- src/corelib/io/qlockfile.h | 6 +--- src/corelib/kernel/qdeadlinetimer.h | 8 ++--- src/corelib/kernel/qobject.h | 6 +--- src/corelib/kernel/qtimer.h | 8 +---- src/corelib/thread/qmutex.h | 8 ++--- .../qdeadlinetimer/tst_qdeadlinetimer.cpp | 8 +---- .../auto/corelib/kernel/qtimer/tst_qtimer.cpp | 10 ------- .../auto/corelib/thread/qmutex/tst_qmutex.cpp | 29 ++----------------- 8 files changed, 10 insertions(+), 73 deletions(-) diff --git a/src/corelib/io/qlockfile.h b/src/corelib/io/qlockfile.h index bc704ea28f..b63194dcd3 100644 --- a/src/corelib/io/qlockfile.h +++ b/src/corelib/io/qlockfile.h @@ -7,9 +7,7 @@ #include #include -#if __has_include() -# include -#endif +#include QT_BEGIN_NAMESPACE @@ -30,7 +28,6 @@ public: void setStaleLockTime(int); int staleLockTime() const; -#if __has_include() bool tryLock(std::chrono::milliseconds timeout) { return tryLock(int(timeout.count())); } void setStaleLockTime(std::chrono::milliseconds value) { setStaleLockTime(int(value.count())); } @@ -39,7 +36,6 @@ public: { return std::chrono::milliseconds(staleLockTime()); } -#endif bool isLocked() const; bool getLockInfo(qint64 *pid, QString *hostname, QString *appname) const; diff --git a/src/corelib/kernel/qdeadlinetimer.h b/src/corelib/kernel/qdeadlinetimer.h index 2220f5dcef..980a2866e0 100644 --- a/src/corelib/kernel/qdeadlinetimer.h +++ b/src/corelib/kernel/qdeadlinetimer.h @@ -16,9 +16,7 @@ #include -#if __has_include() -# include -#endif +#include QT_BEGIN_NAMESPACE @@ -84,7 +82,6 @@ public: QDeadlineTimer &operator-=(qint64 msecs) { *this = *this + (-msecs); return *this; } -#if __has_include() || defined(Q_CLANG_QDOC) template QDeadlineTimer(std::chrono::time_point deadline_, Qt::TimerType type_ = Qt::CoarseTimer) : t2(0) @@ -142,7 +139,6 @@ public: template friend QDeadlineTimer operator+=(QDeadlineTimer &dt, std::chrono::duration value) { return dt = dt + value; } -#endif private: qint64 t1; @@ -156,7 +152,7 @@ public: QPair _q_data() const { return qMakePair(t1, t2); } }; -#if __has_include() && (defined(Q_OS_DARWIN) || defined(Q_OS_LINUX) || (defined(Q_CC_MSVC) && Q_CC_MSVC >= 1900)) +#if defined(Q_OS_DARWIN) || defined(Q_OS_LINUX) || (defined(Q_CC_MSVC) && Q_CC_MSVC >= 1900) // We know for these OS/compilers that the std::chrono::steady_clock uses the same // reference time as QDeadlineTimer diff --git a/src/corelib/kernel/qobject.h b/src/corelib/kernel/qobject.h index 7fa2790208..358f151495 100644 --- a/src/corelib/kernel/qobject.h +++ b/src/corelib/kernel/qobject.h @@ -20,9 +20,7 @@ #include #include -#if __has_include() -# include -#endif +#include QT_BEGIN_NAMESPACE @@ -128,13 +126,11 @@ public: void moveToThread(QThread *thread); int startTimer(int interval, Qt::TimerType timerType = Qt::CoarseTimer); -#if __has_include() Q_ALWAYS_INLINE int startTimer(std::chrono::milliseconds time, Qt::TimerType timerType = Qt::CoarseTimer) { return startTimer(int(time.count()), timerType); } -#endif void killTimer(int id); template diff --git a/src/corelib/kernel/qtimer.h b/src/corelib/kernel/qtimer.h index ca8a81c889..00c06186c3 100644 --- a/src/corelib/kernel/qtimer.h +++ b/src/corelib/kernel/qtimer.h @@ -11,9 +11,7 @@ #include // conceptual inheritance #include -#if __has_include() -# include -#endif +#include QT_BEGIN_NAMESPACE @@ -145,7 +143,6 @@ Q_SIGNALS: void timeout(QPrivateSignal); public: -#if __has_include() || defined(Q_QDOC) void setInterval(std::chrono::milliseconds value) { setInterval(int(value.count())); @@ -175,7 +172,6 @@ public: { start(int(value.count())); } -#endif protected: void timerEvent(QTimerEvent *) override; @@ -192,7 +188,6 @@ private: static void singleShotImpl(int msec, Qt::TimerType timerType, const QObject *receiver, QtPrivate::QSlotObjectBase *slotObj); -#if __has_include() static Qt::TimerType defaultTypeFor(std::chrono::milliseconds interval) { return defaultTypeFor(int(interval.count())); } @@ -202,7 +197,6 @@ private: singleShotImpl(int(interval.count()), timerType, receiver, slotObj); } -#endif }; QT_END_NAMESPACE diff --git a/src/corelib/thread/qmutex.h b/src/corelib/thread/qmutex.h index 036fde729b..ce7b5275ac 100644 --- a/src/corelib/thread/qmutex.h +++ b/src/corelib/thread/qmutex.h @@ -9,10 +9,8 @@ #include #include -#if __has_include() -# include -# include -#endif +#include +#include class tst_QMutex; @@ -31,7 +29,6 @@ class QMutex; class QRecursiveMutex; class QMutexPrivate; -#if __has_include() namespace QtPrivate { template @@ -57,7 +54,6 @@ namespace QtPrivate return ms < maxInt ? int(ms) : maxInt; } } -#endif class Q_CORE_EXPORT QBasicMutex { diff --git a/tests/auto/corelib/kernel/qdeadlinetimer/tst_qdeadlinetimer.cpp b/tests/auto/corelib/kernel/qdeadlinetimer/tst_qdeadlinetimer.cpp index b8ed0031cd..ddb765cf82 100644 --- a/tests/auto/corelib/kernel/qdeadlinetimer/tst_qdeadlinetimer.cpp +++ b/tests/auto/corelib/kernel/qdeadlinetimer/tst_qdeadlinetimer.cpp @@ -8,9 +8,7 @@ #include #include -#if __has_include() -# include -#endif +#include static const int minResolution = 400; // the minimum resolution for the tests @@ -495,9 +493,6 @@ void tst_QDeadlineTimer::expire() void tst_QDeadlineTimer::stdchrono() { -#if !__has_include() - QSKIP("std::chrono not found on this system"); -#else using namespace std::chrono; QFETCH_GLOBAL(Qt::TimerType, timerType); @@ -697,7 +692,6 @@ void tst_QDeadlineTimer::stdchrono() QVERIFY(deadline.deadline() <= (steady_clock::now() + seconds(1) + milliseconds(minResolution))); QVERIFY(deadline.deadline() > (system_clock::now() + seconds(1) - milliseconds(minResolution))); QVERIFY(deadline.deadline() <= (system_clock::now() + seconds(1) + milliseconds(minResolution))); -#endif } QTEST_MAIN(tst_QDeadlineTimer) diff --git a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp index c91aba4790..03a6f1b5aa 100644 --- a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp +++ b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp @@ -240,19 +240,14 @@ void tst_QTimer::remainingTimeDuringActivation() namespace { -#if __has_include() template std::chrono::milliseconds to_ms(T t) { return std::chrono::duration_cast(t); } -#endif } // unnamed namespace void tst_QTimer::basic_chrono() { -#if !__has_include() - QSKIP("This test requires C++11 support"); -#else // duplicates zeroTimer, singleShotTimeout, interval and remainingTime using namespace std::chrono; QTimer timer; @@ -293,7 +288,6 @@ void tst_QTimer::basic_chrono() QCOMPARE(timeoutSpy.count(), 1); QTest::qWait(500); QCOMPARE(timeoutSpy.count(), 1); -#endif } void tst_QTimer::livelock_data() @@ -890,9 +884,6 @@ void tst_QTimer::singleShotToFunctors() void tst_QTimer::singleShot_chrono() { -#if !__has_include() - QSKIP("This test requires C++11 support"); -#else // duplicates singleShotStaticFunctionZeroTimeout and singleShotToFunctors using namespace std::chrono; { @@ -929,7 +920,6 @@ void tst_QTimer::singleShot_chrono() QTRY_COMPARE(count, 3); _e.reset(); -#endif } class DontBlockEvents : public QObject diff --git a/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp b/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp index e78ebbed2e..c03c0c0969 100644 --- a/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp +++ b/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp @@ -67,9 +67,7 @@ enum { waitTime = 100 }; -#if __has_include() static constexpr std::chrono::milliseconds waitTimeAsDuration(waitTime); -#endif void tst_QMutex::convertToMilliseconds_data() { @@ -78,10 +76,6 @@ void tst_QMutex::convertToMilliseconds_data() QTest::addColumn("intValue"); QTest::addColumn("expected"); -#if !__has_include() - QSKIP("This test requires "); -#endif - auto add = [](TimeUnit unit, double d, long long i, qint64 expected) { const QScopedArrayPointer enumName(QTest::toString(unit)); QTest::addRow("%s:%f:%lld", enumName.data(), d, i) @@ -134,9 +128,6 @@ void tst_QMutex::convertToMilliseconds_data() void tst_QMutex::convertToMilliseconds() { -#if !__has_include() - QSKIP("This test requires "); -#else QFETCH(TimeUnit, unit); QFETCH(double, doubleValue); QFETCH(qint64, intValue); @@ -174,7 +165,6 @@ void tst_QMutex::convertToMilliseconds() #undef DO #undef CASE } -#endif } void tst_QMutex::tryLock_non_recursive() @@ -302,10 +292,8 @@ void tst_QMutex::tryLock_non_recursive() thread.wait(); } -void tst_QMutex::try_lock_for_non_recursive() { -#if !__has_include() - QSKIP("This test requires "); -#else +void tst_QMutex::try_lock_for_non_recursive() +{ class Thread : public QThread { public: @@ -427,14 +415,10 @@ void tst_QMutex::try_lock_for_non_recursive() { testsTurn.acquire(); threadsTurn.release(); thread.wait(); -#endif } void tst_QMutex::try_lock_until_non_recursive() { -#if !__has_include() - QSKIP("This test requires "); -#else class Thread : public QThread { public: @@ -556,7 +540,6 @@ void tst_QMutex::try_lock_until_non_recursive() testsTurn.acquire(); threadsTurn.release(); thread.wait(); -#endif } void tst_QMutex::tryLock_recursive() @@ -685,9 +668,6 @@ void tst_QMutex::tryLock_recursive() void tst_QMutex::try_lock_for_recursive() { -#if !__has_include() - QSKIP("This test requires "); -#else class Thread : public QThread { public: @@ -808,14 +788,10 @@ void tst_QMutex::try_lock_for_recursive() testsTurn.acquire(); threadsTurn.release(); thread.wait(); -#endif } void tst_QMutex::try_lock_until_recursive() { -#if !__has_include() - QSKIP("This test requires "); -#else class Thread : public QThread { public: @@ -937,7 +913,6 @@ void tst_QMutex::try_lock_until_recursive() testsTurn.acquire(); threadsTurn.release(); thread.wait(); -#endif } class mutex_Thread : public QThread