Skip to content

Commit

Permalink
QDate: rework stdSysDaysToJulianDay()
Browse files Browse the repository at this point in the history
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 88702cc
and effectively reverts 91f48cc.

Task-number: QTBUG-125610
Pick-to: 6.8 6.7
Change-Id: Idf49fd142cdc78ff8964a36f8c1e326357e1028e
Reviewed-by: Thiago Macieira <[email protected]>
Reviewed-by: Marc Mutz <[email protected]>
  • Loading branch information
isolovev committed Aug 29, 2024
1 parent fbc80ee commit d23764c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/corelib/compat/removed_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ QCborError QCborStreamReader::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(date, time, timeZone, TransitionResolution::LegacyBehavior) {}
Expand Down
21 changes: 8 additions & 13 deletions src/corelib/time/qdatetime.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,28 @@ class Q_CORE_EXPORT QDate
#if (__cpp_lib_chrono >= 201907L && !defined(Q_OS_INTEGRITY)) || defined(Q_QDOC)
QT_POST_CXX17_API_IN_EXPORTED_CLASS
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
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
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
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
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
Expand Down Expand Up @@ -180,9 +180,11 @@ class Q_CORE_EXPORT QDate

// INTEGRITY incident-85878 (timezone and clock_cast are not supported)
#if __cpp_lib_chrono >= 201907L && !defined(Q_OS_INTEGRITY)
#if !QT_CORE_REMOVED_SINCE(6, 7)
QT_POST_CXX17_API_IN_EXPORTED_CLASS
#endif
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();
// minJd() and maxJd() fit into 40 bits.
Expand All @@ -194,13 +196,6 @@ class Q_CORE_EXPORT QDate
}
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

qint64 jd;
Expand Down

0 comments on commit d23764c

Please sign in to comment.