QDate: rework stdSysDaysToJulianDay()

Use !QT_CORE_REMOVED_SINCE(6, 7) to make the function a template
in new C++20 code. The removed_api.cpp will still compile the
exported version, keeping BC.

This simplifies the ifdef'ery around the functions and saves the
need for the QT6_{DECL,CALL}_NEW_OVERLOAD trick.

Picking this change down to 6.7, because the original patch was
also picked to 6.7.

Tested it on MSVC in C++20 mode, and verified that the symbol
is still there. Also tested the case from the linked bugreport,
and verified that it does not give linker errors.

Amends 88702cc87cf830b145c8bff5174748e3719364f9
and effectively reverts 91f48cc4b77b1cfb5a4490c3bed3eb97edd2f85a.

Task-number: QTBUG-125610
Pick-to: 6.7
Change-Id: Idf49fd142cdc78ff8964a36f8c1e326357e1028e
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
(cherry picked from commit d23764c5a12e0d6d26dd54ee5613f7e5b1f9c8af)
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
Ivan Solovev 2024-08-28 14:59:23 +02:00
parent 7fb7972021
commit 665aaf9f6a
2 changed files with 9 additions and 14 deletions

View File

@ -700,7 +700,7 @@ QCborError QCborStreamReader::lastError()
return std::as_const(*this).lastError(); return std::as_const(*this).lastError();
} }
#include "qdatetime.h" #include "qdatetime.h" // also inlined API
QDateTime::QDateTime(QDate date, QTime time, const QTimeZone &timeZone) QDateTime::QDateTime(QDate date, QTime time, const QTimeZone &timeZone)
: QDateTime(date, time, timeZone, TransitionResolution::LegacyBehavior) {} : QDateTime(date, time, timeZone, TransitionResolution::LegacyBehavior) {}

View File

@ -35,28 +35,28 @@ public:
#if __cpp_lib_chrono >= 201907L || defined(Q_QDOC) #if __cpp_lib_chrono >= 201907L || defined(Q_QDOC)
QT_POST_CXX17_API_IN_EXPORTED_CLASS QT_POST_CXX17_API_IN_EXPORTED_CLASS
Q_IMPLICIT constexpr QDate(std::chrono::year_month_day date) noexcept Q_IMPLICIT constexpr QDate(std::chrono::year_month_day date) noexcept
: jd(date.ok() ? stdSysDaysToJulianDay(date QT6_CALL_NEW_OVERLOAD_TAIL) : nullJd()) : jd(date.ok() ? stdSysDaysToJulianDay(date) : nullJd())
{} {}
QT_POST_CXX17_API_IN_EXPORTED_CLASS QT_POST_CXX17_API_IN_EXPORTED_CLASS
Q_IMPLICIT constexpr QDate(std::chrono::year_month_day_last date) noexcept Q_IMPLICIT constexpr QDate(std::chrono::year_month_day_last date) noexcept
: jd(date.ok() ? stdSysDaysToJulianDay(date QT6_CALL_NEW_OVERLOAD_TAIL) : nullJd()) : jd(date.ok() ? stdSysDaysToJulianDay(date) : nullJd())
{} {}
QT_POST_CXX17_API_IN_EXPORTED_CLASS QT_POST_CXX17_API_IN_EXPORTED_CLASS
Q_IMPLICIT constexpr QDate(std::chrono::year_month_weekday date) noexcept Q_IMPLICIT constexpr QDate(std::chrono::year_month_weekday date) noexcept
: jd(date.ok() ? stdSysDaysToJulianDay(date QT6_CALL_NEW_OVERLOAD_TAIL) : nullJd()) : jd(date.ok() ? stdSysDaysToJulianDay(date) : nullJd())
{} {}
QT_POST_CXX17_API_IN_EXPORTED_CLASS QT_POST_CXX17_API_IN_EXPORTED_CLASS
Q_IMPLICIT constexpr QDate(std::chrono::year_month_weekday_last date) noexcept Q_IMPLICIT constexpr QDate(std::chrono::year_month_weekday_last date) noexcept
: jd(date.ok() ? stdSysDaysToJulianDay(date QT6_CALL_NEW_OVERLOAD_TAIL) : nullJd()) : jd(date.ok() ? stdSysDaysToJulianDay(date) : nullJd())
{} {}
QT_POST_CXX17_API_IN_EXPORTED_CLASS QT_POST_CXX17_API_IN_EXPORTED_CLASS
static constexpr QDate fromStdSysDays(const std::chrono::sys_days &days) noexcept static constexpr QDate fromStdSysDays(const std::chrono::sys_days &days) noexcept
{ {
return QDate(stdSysDaysToJulianDay(days QT6_CALL_NEW_OVERLOAD_TAIL)); return QDate(stdSysDaysToJulianDay(days));
} }
QT_POST_CXX17_API_IN_EXPORTED_CLASS QT_POST_CXX17_API_IN_EXPORTED_CLASS
@ -177,9 +177,11 @@ private:
static constexpr inline qint64 unixEpochJd() { return Q_INT64_C(2440588); } static constexpr inline qint64 unixEpochJd() { return Q_INT64_C(2440588); }
#if __cpp_lib_chrono >= 201907L #if __cpp_lib_chrono >= 201907L
#if !QT_CORE_REMOVED_SINCE(6, 7)
QT_POST_CXX17_API_IN_EXPORTED_CLASS QT_POST_CXX17_API_IN_EXPORTED_CLASS
#endif
static constexpr qint64 static constexpr qint64
stdSysDaysToJulianDay(const std::chrono::sys_days &days QT6_DECL_NEW_OVERLOAD_TAIL) noexcept stdSysDaysToJulianDay(const std::chrono::sys_days &days) noexcept
{ {
const auto epochDays = days.time_since_epoch().count(); const auto epochDays = days.time_since_epoch().count();
// minJd() and maxJd() fit into 40 bits. // minJd() and maxJd() fit into 40 bits.
@ -191,13 +193,6 @@ private:
} }
return unixEpochJd() + epochDays; return unixEpochJd() + epochDays;
} }
#if QT_VERSION_MAJOR < 7 && !defined(QT_BOOTSTRAPPED)
static constexpr qint64 stdSysDaysToJulianDay(const std::chrono::sys_days &days) noexcept
{
return stdSysDaysToJulianDay(days QT6_CALL_NEW_OVERLOAD_TAIL);
}
#endif // Qt < 7 and not bootstrapped
#endif // __cpp_lib_chrono >= 201907L #endif // __cpp_lib_chrono >= 201907L
qint64 jd; qint64 jd;