| 1 | // PR libstdc++/103955 |
| 2 | // Verify we don't crash when the floating-point to_chars overloads are passed |
| 3 | // a large precision argument. |
| 4 | // { dg-do run { target c++17 } } |
| 5 | |
| 6 | #include <charconv> |
| 7 | |
| 8 | #include <climits> |
| 9 | #include <initializer_list> |
| 10 | #include <testsuite_hooks.h> |
| 11 | |
| 12 | void |
| 13 | test01() |
| 14 | { |
| 15 | const int size = 12; |
| 16 | char result[size]; |
| 17 | |
| 18 | for (auto fmt : { std::chars_format::fixed, std::chars_format::scientific, |
| 19 | std::chars_format::general, std::chars_format::hex }) |
| 20 | for (int precision : { INT_MAX, INT_MAX-1, INT_MAX-2 }) |
| 21 | { |
| 22 | auto tcr = std::to_chars(result, result+size, 1.337, fmt, precision); |
| 23 | VERIFY( tcr.ptr == result+size && tcr.ec == std::errc::value_too_large ); |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | int |
| 28 | main() |
| 29 | { |
| 30 | test01(); |
| 31 | } |