| 1 | // { dg-do run } |
| 2 | |
| 3 | #include <sstream> |
| 4 | #include <testsuite_hooks.h> |
| 5 | |
| 6 | void |
| 7 | test_pr106248() |
| 8 | { |
| 9 | char buf[5] = {'x', 'x', 'x', 'x', 'x'}; |
| 10 | std::string s(" four"); |
| 11 | std::istringstream in(s); |
| 12 | in >> buf; |
| 13 | #if __cplusplus >= 202002L |
| 14 | // Extraction stops because buffer is full. |
| 15 | VERIFY( in.good() ); |
| 16 | #else |
| 17 | // PR libstdc++/106248 |
| 18 | // Extraction stops because all input has been consumed and eofbit is set. |
| 19 | VERIFY( in.eof() ); |
| 20 | #endif |
| 21 | // Extracted string must be null-terminated. |
| 22 | VERIFY( buf[4] == '\0' ); |
| 23 | VERIFY( std::string(buf) == "four" ); |
| 24 | |
| 25 | in.clear(); |
| 26 | in.str(s); |
| 27 | for (int i = 0; i < 5; ++i) |
| 28 | s[i] = 'x'; |
| 29 | |
| 30 | in.width(5); |
| 31 | in >> buf; |
| 32 | // Extraction stops due to field width, eofbit not set. |
| 33 | VERIFY( in.good() ); |
| 34 | VERIFY( std::string(buf) == "four" ); |
| 35 | } |
| 36 | |
| 37 | int main() |
| 38 | { |
| 39 | test_pr106248(); |
| 40 | } |