diff --git a/include/date/tz.h b/include/date/tz.h index 45fab11..5a0e9e0 100644 --- a/include/date/tz.h +++ b/include/date/tz.h @@ -703,6 +703,11 @@ public: private: template friend class zoned_time; + + template + static + TimeZonePtr2&& + check(TimeZonePtr2&& p); }; using zoned_seconds = zoned_time; @@ -1344,13 +1349,25 @@ to_raw_pointer(Pointer p) noexcept } // namespace detail +template +template +inline +TimeZonePtr2&& +zoned_time::check(TimeZonePtr2&& p) +{ + if (detail::to_raw_pointer(p) == nullptr) + throw std::runtime_error( + "zoned_time constructed with a time zone pointer == nullptr"); + return std::forward(p); +} + template #if !defined(_MSC_VER) || (_MSC_VER > 1916) template #endif inline zoned_time::zoned_time() - : zone_(zoned_traits::default_zone()) + : zone_(check(zoned_traits::default_zone())) {} template @@ -1359,15 +1376,15 @@ template #endif inline zoned_time::zoned_time(const sys_time& st) - : zone_(zoned_traits::default_zone()) + : zone_(check(zoned_traits::default_zone())) , tp_(st) {} template inline zoned_time::zoned_time(TimeZonePtr z) - : zone_(std::move(z)) - {assert(detail::to_raw_pointer(zone_) != nullptr);} + : zone_(check(std::move(z))) + {} #if HAS_STRING_VIEW @@ -1402,7 +1419,7 @@ zoned_time::zoned_time(const zoned_time inline zoned_time::zoned_time(TimeZonePtr z, const sys_time& st) - : zone_(std::move(z)) + : zone_(check(std::move(z))) , tp_(st) {} @@ -1412,7 +1429,7 @@ template #endif inline zoned_time::zoned_time(TimeZonePtr z, const local_time& t) - : zone_(std::move(z)) + : zone_(check(std::move(z))) , tp_(zone_->to_sys(t)) {} @@ -1423,7 +1440,7 @@ template inline zoned_time::zoned_time(TimeZonePtr z, const local_time& t, choose c) - : zone_(std::move(z)) + : zone_(check(std::move(z))) , tp_(zone_->to_sys(t, c)) {} @@ -1432,7 +1449,7 @@ template inline zoned_time::zoned_time(TimeZonePtr z, const zoned_time& zt) - : zone_(std::move(z)) + : zone_(check(std::move(z))) , tp_(zt.tp_) {}