Remove preprocessor conditionals for chrono include

__has_include(<chrono>) 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 <thiago.macieira@intel.com>
This commit is contained in:
Konrad Kujawa 2022-09-14 09:49:00 +02:00
parent 22d4c67234
commit ec2af0a9df
8 changed files with 10 additions and 73 deletions

View File

@ -7,9 +7,7 @@
#include <QtCore/qstring.h> #include <QtCore/qstring.h>
#include <QtCore/qscopedpointer.h> #include <QtCore/qscopedpointer.h>
#if __has_include(<chrono>)
#include <chrono> #include <chrono>
#endif
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
@ -30,7 +28,6 @@ public:
void setStaleLockTime(int); void setStaleLockTime(int);
int staleLockTime() const; int staleLockTime() const;
#if __has_include(<chrono>)
bool tryLock(std::chrono::milliseconds timeout) { return tryLock(int(timeout.count())); } bool tryLock(std::chrono::milliseconds timeout) { return tryLock(int(timeout.count())); }
void setStaleLockTime(std::chrono::milliseconds value) { setStaleLockTime(int(value.count())); } void setStaleLockTime(std::chrono::milliseconds value) { setStaleLockTime(int(value.count())); }
@ -39,7 +36,6 @@ public:
{ {
return std::chrono::milliseconds(staleLockTime()); return std::chrono::milliseconds(staleLockTime());
} }
#endif
bool isLocked() const; bool isLocked() const;
bool getLockInfo(qint64 *pid, QString *hostname, QString *appname) const; bool getLockInfo(qint64 *pid, QString *hostname, QString *appname) const;

View File

@ -16,9 +16,7 @@
#include <limits> #include <limits>
#if __has_include(<chrono>)
#include <chrono> #include <chrono>
#endif
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
@ -84,7 +82,6 @@ public:
QDeadlineTimer &operator-=(qint64 msecs) QDeadlineTimer &operator-=(qint64 msecs)
{ *this = *this + (-msecs); return *this; } { *this = *this + (-msecs); return *this; }
#if __has_include(<chrono>) || defined(Q_CLANG_QDOC)
template <class Clock, class Duration> template <class Clock, class Duration>
QDeadlineTimer(std::chrono::time_point<Clock, Duration> deadline_, QDeadlineTimer(std::chrono::time_point<Clock, Duration> deadline_,
Qt::TimerType type_ = Qt::CoarseTimer) : t2(0) Qt::TimerType type_ = Qt::CoarseTimer) : t2(0)
@ -142,7 +139,6 @@ public:
template <class Rep, class Period> template <class Rep, class Period>
friend QDeadlineTimer operator+=(QDeadlineTimer &dt, std::chrono::duration<Rep, Period> value) friend QDeadlineTimer operator+=(QDeadlineTimer &dt, std::chrono::duration<Rep, Period> value)
{ return dt = dt + value; } { return dt = dt + value; }
#endif
private: private:
qint64 t1; qint64 t1;
@ -156,7 +152,7 @@ public:
QPair<qint64, unsigned> _q_data() const { return qMakePair(t1, t2); } QPair<qint64, unsigned> _q_data() const { return qMakePair(t1, t2); }
}; };
#if __has_include(<chrono>) && (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 // We know for these OS/compilers that the std::chrono::steady_clock uses the same
// reference time as QDeadlineTimer // reference time as QDeadlineTimer

View File

@ -20,9 +20,7 @@
#include <QtCore/qobject_impl.h> #include <QtCore/qobject_impl.h>
#include <QtCore/qbindingstorage.h> #include <QtCore/qbindingstorage.h>
#if __has_include(<chrono>)
#include <chrono> #include <chrono>
#endif
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
@ -128,13 +126,11 @@ public:
void moveToThread(QThread *thread); void moveToThread(QThread *thread);
int startTimer(int interval, Qt::TimerType timerType = Qt::CoarseTimer); int startTimer(int interval, Qt::TimerType timerType = Qt::CoarseTimer);
#if __has_include(<chrono>)
Q_ALWAYS_INLINE Q_ALWAYS_INLINE
int startTimer(std::chrono::milliseconds time, Qt::TimerType timerType = Qt::CoarseTimer) int startTimer(std::chrono::milliseconds time, Qt::TimerType timerType = Qt::CoarseTimer)
{ {
return startTimer(int(time.count()), timerType); return startTimer(int(time.count()), timerType);
} }
#endif
void killTimer(int id); void killTimer(int id);
template<typename T> template<typename T>

View File

@ -11,9 +11,7 @@
#include <QtCore/qbasictimer.h> // conceptual inheritance #include <QtCore/qbasictimer.h> // conceptual inheritance
#include <QtCore/qobject.h> #include <QtCore/qobject.h>
#if __has_include(<chrono>)
#include <chrono> #include <chrono>
#endif
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
@ -145,7 +143,6 @@ Q_SIGNALS:
void timeout(QPrivateSignal); void timeout(QPrivateSignal);
public: public:
#if __has_include(<chrono>) || defined(Q_QDOC)
void setInterval(std::chrono::milliseconds value) void setInterval(std::chrono::milliseconds value)
{ {
setInterval(int(value.count())); setInterval(int(value.count()));
@ -175,7 +172,6 @@ public:
{ {
start(int(value.count())); start(int(value.count()));
} }
#endif
protected: protected:
void timerEvent(QTimerEvent *) override; void timerEvent(QTimerEvent *) override;
@ -192,7 +188,6 @@ private:
static void singleShotImpl(int msec, Qt::TimerType timerType, static void singleShotImpl(int msec, Qt::TimerType timerType,
const QObject *receiver, QtPrivate::QSlotObjectBase *slotObj); const QObject *receiver, QtPrivate::QSlotObjectBase *slotObj);
#if __has_include(<chrono>)
static Qt::TimerType defaultTypeFor(std::chrono::milliseconds interval) static Qt::TimerType defaultTypeFor(std::chrono::milliseconds interval)
{ return defaultTypeFor(int(interval.count())); } { return defaultTypeFor(int(interval.count())); }
@ -202,7 +197,6 @@ private:
singleShotImpl(int(interval.count()), singleShotImpl(int(interval.count()),
timerType, receiver, slotObj); timerType, receiver, slotObj);
} }
#endif
}; };
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -9,10 +9,8 @@
#include <QtCore/qtsan_impl.h> #include <QtCore/qtsan_impl.h>
#include <new> #include <new>
#if __has_include(<chrono>)
#include <chrono> #include <chrono>
#include <limits> #include <limits>
#endif
class tst_QMutex; class tst_QMutex;
@ -31,7 +29,6 @@ class QMutex;
class QRecursiveMutex; class QRecursiveMutex;
class QMutexPrivate; class QMutexPrivate;
#if __has_include(<chrono>)
namespace QtPrivate namespace QtPrivate
{ {
template<class Rep, class Period> template<class Rep, class Period>
@ -57,7 +54,6 @@ namespace QtPrivate
return ms < maxInt ? int(ms) : maxInt; return ms < maxInt ? int(ms) : maxInt;
} }
} }
#endif
class Q_CORE_EXPORT QBasicMutex class Q_CORE_EXPORT QBasicMutex
{ {

View File

@ -8,9 +8,7 @@
#include <QTest> #include <QTest>
#include <QTimer> #include <QTimer>
#if __has_include(<chrono>)
#include <chrono> #include <chrono>
#endif
static const int minResolution = 400; // the minimum resolution for the tests static const int minResolution = 400; // the minimum resolution for the tests
@ -495,9 +493,6 @@ void tst_QDeadlineTimer::expire()
void tst_QDeadlineTimer::stdchrono() void tst_QDeadlineTimer::stdchrono()
{ {
#if !__has_include(<chrono>)
QSKIP("std::chrono not found on this system");
#else
using namespace std::chrono; using namespace std::chrono;
QFETCH_GLOBAL(Qt::TimerType, timerType); QFETCH_GLOBAL(Qt::TimerType, timerType);
@ -697,7 +692,6 @@ void tst_QDeadlineTimer::stdchrono()
QVERIFY(deadline.deadline<steady_clock>() <= (steady_clock::now() + seconds(1) + milliseconds(minResolution))); QVERIFY(deadline.deadline<steady_clock>() <= (steady_clock::now() + seconds(1) + milliseconds(minResolution)));
QVERIFY(deadline.deadline<system_clock>() > (system_clock::now() + seconds(1) - milliseconds(minResolution))); QVERIFY(deadline.deadline<system_clock>() > (system_clock::now() + seconds(1) - milliseconds(minResolution)));
QVERIFY(deadline.deadline<system_clock>() <= (system_clock::now() + seconds(1) + milliseconds(minResolution))); QVERIFY(deadline.deadline<system_clock>() <= (system_clock::now() + seconds(1) + milliseconds(minResolution)));
#endif
} }
QTEST_MAIN(tst_QDeadlineTimer) QTEST_MAIN(tst_QDeadlineTimer)

View File

@ -240,19 +240,14 @@ void tst_QTimer::remainingTimeDuringActivation()
namespace { namespace {
#if __has_include(<chrono>)
template <typename T> template <typename T>
std::chrono::milliseconds to_ms(T t) std::chrono::milliseconds to_ms(T t)
{ return std::chrono::duration_cast<std::chrono::milliseconds>(t); } { return std::chrono::duration_cast<std::chrono::milliseconds>(t); }
#endif
} // unnamed namespace } // unnamed namespace
void tst_QTimer::basic_chrono() void tst_QTimer::basic_chrono()
{ {
#if !__has_include(<chrono>)
QSKIP("This test requires C++11 <chrono> support");
#else
// duplicates zeroTimer, singleShotTimeout, interval and remainingTime // duplicates zeroTimer, singleShotTimeout, interval and remainingTime
using namespace std::chrono; using namespace std::chrono;
QTimer timer; QTimer timer;
@ -293,7 +288,6 @@ void tst_QTimer::basic_chrono()
QCOMPARE(timeoutSpy.count(), 1); QCOMPARE(timeoutSpy.count(), 1);
QTest::qWait(500); QTest::qWait(500);
QCOMPARE(timeoutSpy.count(), 1); QCOMPARE(timeoutSpy.count(), 1);
#endif
} }
void tst_QTimer::livelock_data() void tst_QTimer::livelock_data()
@ -890,9 +884,6 @@ void tst_QTimer::singleShotToFunctors()
void tst_QTimer::singleShot_chrono() void tst_QTimer::singleShot_chrono()
{ {
#if !__has_include(<chrono>)
QSKIP("This test requires C++11 <chrono> support");
#else
// duplicates singleShotStaticFunctionZeroTimeout and singleShotToFunctors // duplicates singleShotStaticFunctionZeroTimeout and singleShotToFunctors
using namespace std::chrono; using namespace std::chrono;
{ {
@ -929,7 +920,6 @@ void tst_QTimer::singleShot_chrono()
QTRY_COMPARE(count, 3); QTRY_COMPARE(count, 3);
_e.reset(); _e.reset();
#endif
} }
class DontBlockEvents : public QObject class DontBlockEvents : public QObject

View File

@ -67,9 +67,7 @@ enum {
waitTime = 100 waitTime = 100
}; };
#if __has_include(<chrono>)
static constexpr std::chrono::milliseconds waitTimeAsDuration(waitTime); static constexpr std::chrono::milliseconds waitTimeAsDuration(waitTime);
#endif
void tst_QMutex::convertToMilliseconds_data() void tst_QMutex::convertToMilliseconds_data()
{ {
@ -78,10 +76,6 @@ void tst_QMutex::convertToMilliseconds_data()
QTest::addColumn<qint64>("intValue"); QTest::addColumn<qint64>("intValue");
QTest::addColumn<qint64>("expected"); QTest::addColumn<qint64>("expected");
#if !__has_include(<chrono>)
QSKIP("This test requires <chrono>");
#endif
auto add = [](TimeUnit unit, double d, long long i, qint64 expected) { auto add = [](TimeUnit unit, double d, long long i, qint64 expected) {
const QScopedArrayPointer<char> enumName(QTest::toString(unit)); const QScopedArrayPointer<char> enumName(QTest::toString(unit));
QTest::addRow("%s:%f:%lld", enumName.data(), d, i) QTest::addRow("%s:%f:%lld", enumName.data(), d, i)
@ -134,9 +128,6 @@ void tst_QMutex::convertToMilliseconds_data()
void tst_QMutex::convertToMilliseconds() void tst_QMutex::convertToMilliseconds()
{ {
#if !__has_include(<chrono>)
QSKIP("This test requires <chrono>");
#else
QFETCH(TimeUnit, unit); QFETCH(TimeUnit, unit);
QFETCH(double, doubleValue); QFETCH(double, doubleValue);
QFETCH(qint64, intValue); QFETCH(qint64, intValue);
@ -174,7 +165,6 @@ void tst_QMutex::convertToMilliseconds()
#undef DO #undef DO
#undef CASE #undef CASE
} }
#endif
} }
void tst_QMutex::tryLock_non_recursive() void tst_QMutex::tryLock_non_recursive()
@ -302,10 +292,8 @@ void tst_QMutex::tryLock_non_recursive()
thread.wait(); thread.wait();
} }
void tst_QMutex::try_lock_for_non_recursive() { void tst_QMutex::try_lock_for_non_recursive()
#if !__has_include(<chrono>) {
QSKIP("This test requires <chrono>");
#else
class Thread : public QThread class Thread : public QThread
{ {
public: public:
@ -427,14 +415,10 @@ void tst_QMutex::try_lock_for_non_recursive() {
testsTurn.acquire(); testsTurn.acquire();
threadsTurn.release(); threadsTurn.release();
thread.wait(); thread.wait();
#endif
} }
void tst_QMutex::try_lock_until_non_recursive() void tst_QMutex::try_lock_until_non_recursive()
{ {
#if !__has_include(<chrono>)
QSKIP("This test requires <chrono>");
#else
class Thread : public QThread class Thread : public QThread
{ {
public: public:
@ -556,7 +540,6 @@ void tst_QMutex::try_lock_until_non_recursive()
testsTurn.acquire(); testsTurn.acquire();
threadsTurn.release(); threadsTurn.release();
thread.wait(); thread.wait();
#endif
} }
void tst_QMutex::tryLock_recursive() void tst_QMutex::tryLock_recursive()
@ -685,9 +668,6 @@ void tst_QMutex::tryLock_recursive()
void tst_QMutex::try_lock_for_recursive() void tst_QMutex::try_lock_for_recursive()
{ {
#if !__has_include(<chrono>)
QSKIP("This test requires <chrono>");
#else
class Thread : public QThread class Thread : public QThread
{ {
public: public:
@ -808,14 +788,10 @@ void tst_QMutex::try_lock_for_recursive()
testsTurn.acquire(); testsTurn.acquire();
threadsTurn.release(); threadsTurn.release();
thread.wait(); thread.wait();
#endif
} }
void tst_QMutex::try_lock_until_recursive() void tst_QMutex::try_lock_until_recursive()
{ {
#if !__has_include(<chrono>)
QSKIP("This test requires <chrono>");
#else
class Thread : public QThread class Thread : public QThread
{ {
public: public:
@ -937,7 +913,6 @@ void tst_QMutex::try_lock_until_recursive()
testsTurn.acquire(); testsTurn.acquire();
threadsTurn.release(); threadsTurn.release();
thread.wait(); thread.wait();
#endif
} }
class mutex_Thread : public QThread class mutex_Thread : public QThread