1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // UNSUPPORTED: 32-bit-pointer
10 
11 // Test that tellp() does not break the stringstream after INT_MAX, due to use
12 // of pbump() that accept int.
13 
14 #include <cassert>
15 #include <climits>
16 #include <sstream>
17 #include <string>
18 
19 int main(int, char**) {
20   std::stringstream ss;
21   std::string payload(INT_MAX - 1, '\0');
22 
23   ss.write(payload.data(), payload.size());
24   assert(ss.tellp() == INT_MAX - 1);
25 
26   ss.write("a", 1);
27   assert(ss.tellp() == INT_MAX);
28 
29   ss.write("b", 1);
30   assert(ss.tellp() == INT_MAX + 1ULL);
31   // it fails only after previous tellp() corrupts the internal field with int
32   // overflow
33   assert(ss.tellp() == INT_MAX + 1ULL);
34 
35   return 0;
36 }
37