Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:24

0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009 
0010 // For information see https://libcxx.llvm.org/DesignDocs/TimeZone.html
0011 
0012 #ifndef _LIBCPP___CXX03___CHRONO_EXCEPTION_H
0013 #define _LIBCPP___CXX03___CHRONO_EXCEPTION_H
0014 
0015 #include <__cxx03/version>
0016 // Enable the contents of the header only when libc++ was built with experimental features enabled.
0017 #if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
0018 
0019 #  include <__cxx03/__chrono/calendar.h>
0020 #  include <__cxx03/__chrono/local_info.h>
0021 #  include <__cxx03/__chrono/time_point.h>
0022 #  include <__cxx03/__config>
0023 #  include <__cxx03/__configuration/availability.h>
0024 #  include <__cxx03/__verbose_abort>
0025 #  include <__cxx03/format>
0026 #  include <__cxx03/stdexcept>
0027 #  include <__cxx03/string>
0028 
0029 #  if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0030 #    pragma GCC system_header
0031 #  endif
0032 
0033 _LIBCPP_BEGIN_NAMESPACE_STD
0034 
0035 #  if _LIBCPP_STD_VER >= 20
0036 
0037 namespace chrono {
0038 
0039 class nonexistent_local_time : public runtime_error {
0040 public:
0041   template <class _Duration>
0042   _LIBCPP_HIDE_FROM_ABI nonexistent_local_time(const local_time<_Duration>& __time, const local_info& __info)
0043       : runtime_error{__create_message(__time, __info)} {
0044     // [time.zone.exception.nonexist]/2
0045     //   Preconditions: i.result == local_info::nonexistent is true.
0046     // The value of __info.result is not used.
0047     _LIBCPP_ASSERT_PEDANTIC(__info.result == local_info::nonexistent,
0048                             "creating an nonexistent_local_time from a local_info that is not non-existent");
0049   }
0050 
0051   _LIBCPP_HIDE_FROM_ABI nonexistent_local_time(const nonexistent_local_time&)            = default;
0052   _LIBCPP_HIDE_FROM_ABI nonexistent_local_time& operator=(const nonexistent_local_time&) = default;
0053 
0054   _LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI ~nonexistent_local_time() override; // exported as key function
0055 
0056 private:
0057   template <class _Duration>
0058   _LIBCPP_HIDE_FROM_ABI string __create_message(const local_time<_Duration>& __time, const local_info& __info) {
0059     return std::format(
0060         R"({} is in a gap between
0061 {} {} and
0062 {} {} which are both equivalent to
0063 {} UTC)",
0064         __time,
0065         local_seconds{__info.first.end.time_since_epoch()} + __info.first.offset,
0066         __info.first.abbrev,
0067         local_seconds{__info.second.begin.time_since_epoch()} + __info.second.offset,
0068         __info.second.abbrev,
0069         __info.first.end);
0070   }
0071 };
0072 
0073 template <class _Duration>
0074 _LIBCPP_NORETURN _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI void __throw_nonexistent_local_time(
0075     [[maybe_unused]] const local_time<_Duration>& __time, [[maybe_unused]] const local_info& __info) {
0076 #    ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0077   throw nonexistent_local_time(__time, __info);
0078 #    else
0079   _LIBCPP_VERBOSE_ABORT("nonexistent_local_time was thrown in -fno-exceptions mode");
0080 #    endif
0081 }
0082 
0083 class ambiguous_local_time : public runtime_error {
0084 public:
0085   template <class _Duration>
0086   _LIBCPP_HIDE_FROM_ABI ambiguous_local_time(const local_time<_Duration>& __time, const local_info& __info)
0087       : runtime_error{__create_message(__time, __info)} {
0088     // [time.zone.exception.ambig]/2
0089     //   Preconditions: i.result == local_info::ambiguous is true.
0090     // The value of __info.result is not used.
0091     _LIBCPP_ASSERT_PEDANTIC(__info.result == local_info::ambiguous,
0092                             "creating an ambiguous_local_time from a local_info that is not ambiguous");
0093   }
0094 
0095   _LIBCPP_HIDE_FROM_ABI ambiguous_local_time(const ambiguous_local_time&)            = default;
0096   _LIBCPP_HIDE_FROM_ABI ambiguous_local_time& operator=(const ambiguous_local_time&) = default;
0097 
0098   _LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI ~ambiguous_local_time() override; // exported as key function
0099 
0100 private:
0101   template <class _Duration>
0102   _LIBCPP_HIDE_FROM_ABI string __create_message(const local_time<_Duration>& __time, const local_info& __info) {
0103     return std::format(
0104         // There are two spaces after the full-stop; this has been verified
0105         // in the sources of the Standard.
0106         R"({0} is ambiguous.  It could be
0107 {0} {1} == {2} UTC or
0108 {0} {3} == {4} UTC)",
0109         __time,
0110         __info.first.abbrev,
0111         __time - __info.first.offset,
0112         __info.second.abbrev,
0113         __time - __info.second.offset);
0114   }
0115 };
0116 
0117 template <class _Duration>
0118 _LIBCPP_NORETURN _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI void __throw_ambiguous_local_time(
0119     [[maybe_unused]] const local_time<_Duration>& __time, [[maybe_unused]] const local_info& __info) {
0120 #    ifndef _LIBCPP_HAS_NO_EXCEPTIONS
0121   throw ambiguous_local_time(__time, __info);
0122 #    else
0123   _LIBCPP_VERBOSE_ABORT("ambiguous_local_time was thrown in -fno-exceptions mode");
0124 #    endif
0125 }
0126 
0127 } // namespace chrono
0128 
0129 #  endif // _LIBCPP_STD_VER >= 20
0130 
0131 _LIBCPP_END_NAMESPACE_STD
0132 
0133 #endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
0134 
0135 #endif // _LIBCPP___CXX03___CHRONO_EXCEPTION_H