| 1 |
// Copyright (C) 2020-2025 Free Software Foundation, Inc. |
| 2 |
// |
| 3 |
// This file is part of the GNU ISO C++ Library. This library is free |
| 4 |
// software; you can redistribute it and/or modify it under the |
| 5 |
// terms of the GNU General Public License as published by the |
| 6 |
// Free Software Foundation; either version 3, or (at your option) |
| 7 |
// any later version. |
| 8 |
|
| 9 |
// This library is distributed in the hope that it will be useful, |
| 10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
// GNU General Public License for more details. |
| 13 |
|
| 14 |
// You should have received a copy of the GNU General Public License along |
| 15 |
// with this library; see the file COPYING3. If not see |
| 16 |
// <http://www.gnu.org/licenses/>. |
| 17 |
|
| 18 |
// { dg-do compile { target c++20 } } |
| 19 |
// { dg-add-options no_pch } |
| 20 |
|
| 21 |
#include <chrono> |
| 22 |
|
| 23 |
// std::chrono::tzdb is not defined for the old std::string ABI. |
| 24 |
#if _GLIBCXX_USE_CXX_ABI |
| 25 |
# define EXPECTED_VALUE 201907L |
| 26 |
#else |
| 27 |
# define EXPECTED_VALUE 201611L |
| 28 |
#endif |
| 29 |
|
| 30 |
#ifndef __cpp_lib_chrono |
| 31 |
# error "Feature test macro for chrono is missing in <chrono>" |
| 32 |
#elif __cpp_lib_chrono < EXPECTED_VALUE |
| 33 |
# error "Feature test macro for chrono has wrong value in <chrono>" |
| 34 |
#endif |
| 35 |
|
| 36 |
namespace __gnu_test |
| 37 |
{ |
| 38 |
// Check for the new additions to <chrono> in C++20 |
| 39 |
|
| 40 |
using std::chrono::is_clock; |
| 41 |
using std::chrono::is_clock_v; |
| 42 |
|
| 43 |
using std::chrono::days; |
| 44 |
using std::chrono::weeks; |
| 45 |
using std::chrono::years; |
| 46 |
using std::chrono::months; |
| 47 |
|
| 48 |
using std::chrono::sys_time; |
| 49 |
using std::chrono::sys_seconds; |
| 50 |
using std::chrono::sys_days; |
| 51 |
|
| 52 |
using std::chrono::utc_clock; |
| 53 |
using std::chrono::utc_time; |
| 54 |
using std::chrono::utc_seconds; |
| 55 |
|
| 56 |
using std::chrono::leap_second_info; |
| 57 |
using std::chrono::get_leap_second_info; |
| 58 |
|
| 59 |
using std::chrono::tai_clock; |
| 60 |
using std::chrono::tai_time; |
| 61 |
using std::chrono::tai_seconds; |
| 62 |
|
| 63 |
using std::chrono::gps_clock; |
| 64 |
using std::chrono::gps_time; |
| 65 |
using std::chrono::gps_seconds; |
| 66 |
|
| 67 |
using std::chrono::file_clock; |
| 68 |
using std::chrono::file_time; |
| 69 |
|
| 70 |
using std::chrono::local_t; |
| 71 |
using std::chrono::local_time; |
| 72 |
using std::chrono::local_seconds; |
| 73 |
using std::chrono::local_days; |
| 74 |
|
| 75 |
using std::chrono::clock_time_conversion; |
| 76 |
using std::chrono::clock_cast; |
| 77 |
|
| 78 |
using std::chrono::last_spec; |
| 79 |
|
| 80 |
using std::chrono::day; |
| 81 |
using std::chrono::month; |
| 82 |
using std::chrono::year; |
| 83 |
using std::chrono::weekday; |
| 84 |
using std::chrono::weekday_indexed; |
| 85 |
using std::chrono::weekday_last; |
| 86 |
using std::chrono::month_day; |
| 87 |
using std::chrono::month_day_last; |
| 88 |
using std::chrono::month_weekday; |
| 89 |
using std::chrono::month_weekday_last; |
| 90 |
using std::chrono::year_month; |
| 91 |
using std::chrono::year_month_day; |
| 92 |
using std::chrono::year_month_day_last; |
| 93 |
using std::chrono::year_month_weekday; |
| 94 |
using std::chrono::year_month_weekday_last; |
| 95 |
using std::chrono::year_month; |
| 96 |
using std::chrono::year_month_day; |
| 97 |
|
| 98 |
using std::chrono::hh_mm_ss; |
| 99 |
using std::chrono::is_am; |
| 100 |
using std::chrono::is_pm; |
| 101 |
using std::chrono::make12; |
| 102 |
using std::chrono::make24; |
| 103 |
|
| 104 |
#if __cpp_lib_chrono >= 201803L |
| 105 |
using std::chrono::tzdb; |
| 106 |
using std::chrono::tzdb_list; |
| 107 |
using std::chrono::get_tzdb; |
| 108 |
using std::chrono::get_tzdb_list; |
| 109 |
using std::chrono::locate_zone; |
| 110 |
using std::chrono::current_zone; |
| 111 |
|
| 112 |
using std::chrono::reload_tzdb; |
| 113 |
using std::chrono::remote_version; |
| 114 |
|
| 115 |
using std::chrono::nonexistent_local_time; |
| 116 |
using std::chrono::ambiguous_local_time; |
| 117 |
|
| 118 |
using std::chrono::sys_info; |
| 119 |
using std::chrono::local_info; |
| 120 |
|
| 121 |
using std::chrono::choose; |
| 122 |
using std::chrono::time_zone; |
| 123 |
|
| 124 |
using std::chrono::zoned_traits; |
| 125 |
using std::chrono::zoned_time; |
| 126 |
using std::chrono::zoned_seconds; |
| 127 |
|
| 128 |
using std::chrono::leap_second; |
| 129 |
|
| 130 |
using std::chrono::time_zone_link; |
| 131 |
#endif |
| 132 |
|
| 133 |
using std::chrono::local_time_format; |
| 134 |
|
| 135 |
using std::chrono::from_stream; |
| 136 |
using std::chrono::parse; |
| 137 |
|
| 138 |
using std::chrono::last; |
| 139 |
using std::chrono::Sunday; |
| 140 |
using std::chrono::Monday; |
| 141 |
using std::chrono::Tuesday; |
| 142 |
using std::chrono::Wednesday; |
| 143 |
using std::chrono::Thursday; |
| 144 |
using std::chrono::Friday; |
| 145 |
using std::chrono::Saturday; |
| 146 |
|
| 147 |
using std::chrono::January; |
| 148 |
using std::chrono::February; |
| 149 |
using std::chrono::March; |
| 150 |
using std::chrono::April; |
| 151 |
using std::chrono::May; |
| 152 |
using std::chrono::June; |
| 153 |
using std::chrono::July; |
| 154 |
using std::chrono::August; |
| 155 |
using std::chrono::September; |
| 156 |
using std::chrono::October; |
| 157 |
using std::chrono::November; |
| 158 |
using std::chrono::December; |
| 159 |
|
| 160 |
using std::chrono_literals::operator""d; |
| 161 |
using std::chrono_literals::operator""y; |
| 162 |
|
| 163 |
template<typename> |
| 164 |
constexpr bool is_duration = false; |
| 165 |
template<typename R, typename P> |
| 166 |
constexpr bool is_duration<std::chrono::duration<R, P>> = true; |
| 167 |
|
| 168 |
static_assert( is_duration<days> ); |
| 169 |
static_assert( is_duration<weeks> ); |
| 170 |
static_assert( is_duration<years> ); |
| 171 |
static_assert( is_duration<months> ); |
| 172 |
|
| 173 |
template<typename D, typename P> |
| 174 |
constexpr bool has_period = std::is_same_v<typename D::period, P>; |
| 175 |
|
| 176 |
using std::ratio; |
| 177 |
using std::ratio_multiply; |
| 178 |
using std::ratio_divide; |
| 179 |
using std::chrono::hours; |
| 180 |
static_assert( has_period<days, ratio_multiply<ratio<24>, hours::period>> ); |
| 181 |
static_assert( has_period<weeks, ratio_multiply<ratio<7>, days::period>> ); |
| 182 |
static_assert( has_period<years, |
| 183 |
ratio_multiply<ratio<146097, 400>, days::period>> ); |
| 184 |
static_assert( has_period<months, ratio_divide<years::period, ratio<12>>> ); |
| 185 |
|
| 186 |
template<typename> |
| 187 |
constexpr bool is_time_point = false; |
| 188 |
template<typename C, typename D> |
| 189 |
constexpr bool is_time_point<std::chrono::time_point<C, D>> = true; |
| 190 |
|
| 191 |
static_assert( is_time_point<sys_time<std::chrono::milliseconds>> ); |
| 192 |
static_assert( is_time_point<sys_seconds> ); |
| 193 |
static_assert( is_time_point<sys_days> ); |
| 194 |
|
| 195 |
static_assert( std::is_class_v<local_t> ); |
| 196 |
static_assert( is_time_point<local_time<std::chrono::milliseconds>> ); |
| 197 |
static_assert( is_time_point<local_seconds> ); |
| 198 |
static_assert( is_time_point<local_days> ); |
| 199 |
|
| 200 |
static_assert( std::is_class_v<file_clock> ); |
| 201 |
static_assert( is_time_point<file_time<std::chrono::milliseconds>> ); |
| 202 |
} |