| 1 |
// { dg-do run { target c++20 } } |
| 2 |
// { dg-timeout-factor 2 } |
| 3 |
// { dg-require-namedlocale "en_US.ISO8859-1" } |
| 4 |
|
| 5 |
// PR libstdc++/114244 Need to use round when parsing fractional seconds |
| 6 |
|
| 7 |
#include <chrono> |
| 8 |
#include <sstream> |
| 9 |
#include <testsuite_hooks.h> |
| 10 |
|
| 11 |
void |
| 12 |
test_pr114244() |
| 13 |
{ |
| 14 |
using namespace std::chrono; |
| 15 |
seconds s; |
| 16 |
milliseconds ms; |
| 17 |
microseconds us; |
| 18 |
|
| 19 |
std::istringstream is; |
| 20 |
|
| 21 |
is.clear(); |
| 22 |
is.str("0.002"); |
| 23 |
VERIFY( is >> parse("%S", ms) ); |
| 24 |
VERIFY( ms == 2ms ); // not 1ms |
| 25 |
|
| 26 |
is.imbue(std::locale(ISO_8859(1,en_US))); |
| 27 |
is.clear(); |
| 28 |
is.str("0.002"); |
| 29 |
VERIFY( is >> parse("%S", us) ); |
| 30 |
VERIFY( us == 2000us ); // not 1999us |
| 31 |
} |
| 32 |
|
| 33 |
int main() |
| 34 |
{ |
| 35 |
test_pr114244(); |
| 36 |
} |