| 1 |
// { dg-do compile { target c++20 } } |
| 2 |
|
| 3 |
// PR libstdc++/109772 Memory layout optimization of chrono::hh_mm_ss is wrong |
| 4 |
|
| 5 |
#include <chrono> |
| 6 |
#include <testsuite_hooks.h> |
| 7 |
|
| 8 |
using std::chrono::hh_mm_ss; |
| 9 |
using std::chrono::duration; |
| 10 |
using std::ratio; |
| 11 |
|
| 12 |
constexpr bool |
| 13 |
test_truncated() |
| 14 |
{ |
| 15 |
using int_1_1024 = duration<int, ratio<1, 1024>>; |
| 16 |
static_assert( hh_mm_ss<int_1_1024>::fractional_width == 10 ); |
| 17 |
|
| 18 |
hh_mm_ss<int_1_1024> t1(int_1_1024(487)); |
| 19 |
VERIFY( t1.subseconds().count() == (10'000'000'000 * 487 / 1024) ); |
| 20 |
|
| 21 |
hh_mm_ss<int_1_1024> t2(int_1_1024(1023)); |
| 22 |
VERIFY( t2.subseconds().count() == (10'000'000'000 * 1023 / 1024) ); |
| 23 |
|
| 24 |
return true; |
| 25 |
} |
| 26 |
|
| 27 |
static_assert( test_truncated() ); |
| 28 |
|
| 29 |
// Check for ambiguous partial specializations of hh_mm_ss::__subseconds: |
| 30 |
static_assert( hh_mm_ss<duration<char, ratio<1, 11>>>::fractional_width == 6 ); |