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 // <streambuf>
10 
11 // template <class charT, class traits = char_traits<charT> >
12 // class basic_streambuf;
13 
14 // void pbump(int n);
15 //
16 // REQUIRES: long_tests
17 
18 // Unsupported for no-exceptions builds because they have no way to report an
19 // allocation failure when attempting to allocate the 2GiB string.
20 // UNSUPPORTED: no-exceptions
21 
22 #include <sstream>
23 #include <cassert>
24 #include "test_macros.h"
25 
26 struct SB : std::stringbuf
27 {
SBSB28   SB() : std::stringbuf(std::ios::ate|std::ios::out) { }
pubpbaseSB29   const char* pubpbase() const { return pbase(); }
pubpptrSB30   const char* pubpptr() const { return pptr(); }
31 };
32 
main(int,char **)33 int main(int, char**)
34 {
35     try {
36         std::string str(2147483648, 'a');
37         SB sb;
38         sb.str(str);
39         assert(sb.pubpbase() <= sb.pubpptr());
40     }
41     catch (const std::length_error &) {} // maybe the string can't take 2GB
42     catch (const std::bad_alloc    &) {} // maybe we don't have enough RAM
43 
44   return 0;
45 }
46