QDate: fix C++20 builds with MSVC

Commit c4f7dba81e43c11c1e71c19ef7f0b5acad119e60 reworked the C++20
QDate constructors and introduced a helper stdSysDaysToJulianDay()
method. However, the QT_POST_CXX17_API_IN_EXPORTED_CLASS was not used
on this new helper function.
As a result, an application which is built with C++20 but uses a
pre-built QtCore that is built with C++17 cannot call QDate constructors
with the new std::chorono types.

An obvious fix is to add the missing macro to the function.
However, we cannot do it directly, because the function is exported
in C++20 builds, and adding the macro will unexport it.

Use QT6_{DECL,CALL}_NEW_OVERLOAD_TAIL macros to add a new overload of
the stdSysDaysToJulianDay() function and mark it as
QT_POST_CXX17_API_IN_EXPORTED_CLASS.

Keep the old function under the QT_VERSION < Qt 7 check to keep BC.

Amends c4f7dba81e43c11c1e71c19ef7f0b5acad119e60.

Fixes: QTBUG-125610
Change-Id: I999354da51ee58c3691dbc1c0351be15a18a268b
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit 88702cc87cf830b145c8bff5174748e3719364f9)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Ivan Solovev 2024-05-24 10:53:51 +02:00 committed by Qt Cherry-pick Bot
parent eb4e5b798d
commit d3c060defa

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) : nullJd()) : jd(date.ok() ? stdSysDaysToJulianDay(date QT6_CALL_NEW_OVERLOAD_TAIL) : 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) : nullJd()) : jd(date.ok() ? stdSysDaysToJulianDay(date QT6_CALL_NEW_OVERLOAD_TAIL) : 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) : nullJd()) : jd(date.ok() ? stdSysDaysToJulianDay(date QT6_CALL_NEW_OVERLOAD_TAIL) : 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) : nullJd()) : jd(date.ok() ? stdSysDaysToJulianDay(date QT6_CALL_NEW_OVERLOAD_TAIL) : 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)); return QDate(stdSysDaysToJulianDay(days QT6_CALL_NEW_OVERLOAD_TAIL));
} }
QT_POST_CXX17_API_IN_EXPORTED_CLASS QT_POST_CXX17_API_IN_EXPORTED_CLASS
@ -177,7 +177,9 @@ 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
static constexpr qint64 stdSysDaysToJulianDay(const std::chrono::sys_days &days) noexcept QT_POST_CXX17_API_IN_EXPORTED_CLASS
static constexpr qint64
stdSysDaysToJulianDay(const std::chrono::sys_days &days QT6_DECL_NEW_OVERLOAD_TAIL) 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.
@ -189,6 +191,13 @@ private:
} }
return unixEpochJd() + epochDays; return unixEpochJd() + epochDays;
} }
#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
static constexpr qint64 stdSysDaysToJulianDay(const std::chrono::sys_days &days) noexcept
{
return stdSysDaysToJulianDay(days QT6_CALL_NEW_OVERLOAD_TAIL);
}
#endif // QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
#endif // __cpp_lib_chrono >= 201907L #endif // __cpp_lib_chrono >= 201907L
qint64 jd; qint64 jd;