Path: blob/main/contrib/llvm-project/libcxx/include/__chrono/exception.h
35262 views
// -*- C++ -*-1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//89// For information see https://libcxx.llvm.org/DesignDocs/TimeZone.html1011#ifndef _LIBCPP___CHRONO_EXCEPTION_H12#define _LIBCPP___CHRONO_EXCEPTION_H1314#include <version>15// Enable the contents of the header only when libc++ was built with experimental features enabled.16#if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)1718# include <__chrono/calendar.h>19# include <__chrono/local_info.h>20# include <__chrono/time_point.h>21# include <__config>22# include <__configuration/availability.h>23# include <__verbose_abort>24# include <format>25# include <stdexcept>26# include <string>2728# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)29# pragma GCC system_header30# endif3132_LIBCPP_BEGIN_NAMESPACE_STD3334# if _LIBCPP_STD_VER >= 203536namespace chrono {3738class nonexistent_local_time : public runtime_error {39public:40template <class _Duration>41_LIBCPP_HIDE_FROM_ABI nonexistent_local_time(const local_time<_Duration>& __time, const local_info& __info)42: runtime_error{__create_message(__time, __info)} {43// [time.zone.exception.nonexist]/244// Preconditions: i.result == local_info::nonexistent is true.45// The value of __info.result is not used.46_LIBCPP_ASSERT_PEDANTIC(__info.result == local_info::nonexistent,47"creating an nonexistent_local_time from a local_info that is not non-existent");48}4950_LIBCPP_HIDE_FROM_ABI nonexistent_local_time(const nonexistent_local_time&) = default;51_LIBCPP_HIDE_FROM_ABI nonexistent_local_time& operator=(const nonexistent_local_time&) = default;5253_LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI ~nonexistent_local_time() override; // exported as key function5455private:56template <class _Duration>57_LIBCPP_HIDE_FROM_ABI string __create_message(const local_time<_Duration>& __time, const local_info& __info) {58return std::format(59R"({} is in a gap between60{} {} and61{} {} which are both equivalent to62{} UTC)",63__time,64local_seconds{__info.first.end.time_since_epoch()} + __info.first.offset,65__info.first.abbrev,66local_seconds{__info.second.begin.time_since_epoch()} + __info.second.offset,67__info.second.abbrev,68__info.first.end);69}70};7172template <class _Duration>73_LIBCPP_NORETURN _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI void __throw_nonexistent_local_time(74[[maybe_unused]] const local_time<_Duration>& __time, [[maybe_unused]] const local_info& __info) {75# ifndef _LIBCPP_HAS_NO_EXCEPTIONS76throw nonexistent_local_time(__time, __info);77# else78_LIBCPP_VERBOSE_ABORT("nonexistent_local_time was thrown in -fno-exceptions mode");79# endif80}8182class ambiguous_local_time : public runtime_error {83public:84template <class _Duration>85_LIBCPP_HIDE_FROM_ABI ambiguous_local_time(const local_time<_Duration>& __time, const local_info& __info)86: runtime_error{__create_message(__time, __info)} {87// [time.zone.exception.ambig]/288// Preconditions: i.result == local_info::ambiguous is true.89// The value of __info.result is not used.90_LIBCPP_ASSERT_PEDANTIC(__info.result == local_info::ambiguous,91"creating an ambiguous_local_time from a local_info that is not ambiguous");92}9394_LIBCPP_HIDE_FROM_ABI ambiguous_local_time(const ambiguous_local_time&) = default;95_LIBCPP_HIDE_FROM_ABI ambiguous_local_time& operator=(const ambiguous_local_time&) = default;9697_LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI ~ambiguous_local_time() override; // exported as key function9899private:100template <class _Duration>101_LIBCPP_HIDE_FROM_ABI string __create_message(const local_time<_Duration>& __time, const local_info& __info) {102return std::format(103// There are two spaces after the full-stop; this has been verified104// in the sources of the Standard.105R"({0} is ambiguous. It could be106{0} {1} == {2} UTC or107{0} {3} == {4} UTC)",108__time,109__info.first.abbrev,110__time - __info.first.offset,111__info.second.abbrev,112__time - __info.second.offset);113}114};115116template <class _Duration>117_LIBCPP_NORETURN _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI void __throw_ambiguous_local_time(118[[maybe_unused]] const local_time<_Duration>& __time, [[maybe_unused]] const local_info& __info) {119# ifndef _LIBCPP_HAS_NO_EXCEPTIONS120throw ambiguous_local_time(__time, __info);121# else122_LIBCPP_VERBOSE_ABORT("ambiguous_local_time was thrown in -fno-exceptions mode");123# endif124}125126} // namespace chrono127128# endif // _LIBCPP_STD_VER >= 20129130_LIBCPP_END_NAMESPACE_STD131132#endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)133134#endif // _LIBCPP___CHRONO_EXCEPTION_H135136137