Debian Codegraph @

libstdc++-v3/testsuite/20_util/duration/arithmetic/overflow_c++20.cc

raw
1 // { dg-do run { target c++20 } }
2
3 #include <chrono>
4 #include <cstdint>
5 #include <testsuite_hooks.h>
6
7 void
8 test_overflow()
9 {
10 using namespace std::chrono;
11
12 using seconds32_t = duration<std::int_least32_t>;
13 seconds32_t t = 14h + 25min + 55s;
14 auto snow = sys_days(1854y/December/11);
15 auto snow_t = snow + t;
16 // Fails if days::rep is 32-bit:
17 VERIFY( snow_t.time_since_epoch() < seconds::zero() );
18 auto y = floor<years>(snow);
19 auto y_t = y + t;
20 // Fails if years::rep is 32-bit:
21 VERIFY( y_t.time_since_epoch() < seconds::zero() );
22 VERIFY( y_t < snow_t );
23 }
24
25 int main()
26 {
27 test_overflow();
28 }