From f974ea6f862de06ad89a6f1aa89df2b71c31c01f Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 18 Aug 2023 20:54:14 +0200 Subject: [PATCH] QDeadlineTimer: make the (Qt::TimerType) ctor explicit Qt::TimerType is not a faithful representation of a QDeadlineTimer. It's missing the actual deadline, and so should not be allowed to participate in implicit conversions. Consider whether you'd like to see such code: foo.setTimeout(Qt::PreciseTimer); // HU??? So split the old (TimerType = CoarseTimer) ctor into an explicit default ctor (applying NSDMI to make it =default'able) and a new explicit (TimerType) ctor. [ChangeLog][Potentially Source-Incompatible Changes][QtCore] The QDeadlineTimer(Qt::TimerType) constructor is no longer implicit. To keep old source working, wrap the Qt::TimerType argument in QDeadlineTimer{}. This is backwards-compatible with older Qt versions. [ChangeLog][QtCore][QDeadlineTimer] The (Qt::TimerType) constructor is now explicit (was: implicit). Found in API-review. Change-Id: I72aaaad5201bd288a6fd6af398573aaa9d0eda5a Reviewed-by: Ivan Solovev Reviewed-by: Thiago Macieira (cherry picked from commit 17f2b6d2e9379d7edaf5acd17a6547ca46b12f2b) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/kernel/qdeadlinetimer.cpp | 4 +++- src/corelib/kernel/qdeadlinetimer.h | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/corelib/kernel/qdeadlinetimer.cpp b/src/corelib/kernel/qdeadlinetimer.cpp index 4e15b3b80f8..731ff4e9e11 100644 --- a/src/corelib/kernel/qdeadlinetimer.cpp +++ b/src/corelib/kernel/qdeadlinetimer.cpp @@ -131,10 +131,12 @@ static qint64 add_saturate(qint64 t1, Duration1 dur, Durations... extra) */ /*! + \fn QDeadlineTimer::QDeadlineTimer() \fn QDeadlineTimer::QDeadlineTimer(Qt::TimerType timerType) Constructs an expired QDeadlineTimer object. For this object, - remainingTime() will return 0. + remainingTime() will return 0. If \a timerType is not set, then the object + will use the \l{Qt::CoarseTimer}{coarse} \l{QDeadlineTimer#Timer types}{timer type}. The timer type \a timerType may be ignored, since the timer is already expired. Similarly, for optimization purposes, this function will not diff --git a/src/corelib/kernel/qdeadlinetimer.h b/src/corelib/kernel/qdeadlinetimer.h index b872422add0..57c771de9a2 100644 --- a/src/corelib/kernel/qdeadlinetimer.h +++ b/src/corelib/kernel/qdeadlinetimer.h @@ -26,7 +26,8 @@ public: enum class ForeverConstant { Forever }; static constexpr ForeverConstant Forever = ForeverConstant::Forever; - constexpr QDeadlineTimer(Qt::TimerType type_ = Qt::CoarseTimer) noexcept + constexpr QDeadlineTimer() noexcept = default; + constexpr explicit QDeadlineTimer(Qt::TimerType type_) noexcept : type(type_) {} constexpr QDeadlineTimer(ForeverConstant, Qt::TimerType type_ = Qt::CoarseTimer) noexcept : t1((std::numeric_limits::max)()), type(type_) {} @@ -142,7 +143,7 @@ private: #if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) unsigned t2 = 0; #endif - unsigned type; + unsigned type = Qt::CoarseTimer; qint64 rawRemainingTimeNSecs() const noexcept; };