| 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 | // UNSUPPORTED: c++03 |
| 12 | |
| 13 | // template <class charT, class traits = char_traits<charT> > |
| 14 | // class basic_streambuf; |
| 15 | |
| 16 | // void pbump(int n); |
| 17 | // |
| 18 | // REQUIRES: long_tests |
| 19 | |
| 20 | // Unsupported for no-exceptions builds because they have no way to report an |
| 21 | // allocation failure when attempting to allocate the 2GiB string. |
| 22 | // UNSUPPORTED: no-exceptions |
| 23 | |
| 24 | // Android devices frequently don't have enough memory to run this test. Rather |
| 25 | // than throw std::bad_alloc, exhausting memory triggers the OOM Killer. |
| 26 | // UNSUPPORTED: LIBCXX-ANDROID-FIXME |
| 27 | |
| 28 | #include <sstream> |
| 29 | #include <cassert> |
| 30 | #include "test_macros.h" |
| 31 | |
| 32 | struct SB : std::stringbuf |
| 33 | { |
| 34 | SB() : std::stringbuf(std::ios::ate|std::ios::out) { } |
| 35 | const char* pubpbase() const { return pbase(); } |
| 36 | const char* pubpptr() const { return pptr(); } |
| 37 | }; |
| 38 | |
| 39 | int main(int, char**) |
| 40 | { |
| 41 | try { |
| 42 | std::string str(2147483648, 'a'); |
| 43 | SB sb; |
| 44 | sb.str(s: str); |
| 45 | assert(sb.pubpbase() <= sb.pubpptr()); |
| 46 | } |
| 47 | catch (const std::length_error &) {} // maybe the string can't take 2GB |
| 48 | catch (const std::bad_alloc &) {} // maybe we don't have enough RAM |
| 49 | |
| 50 | return 0; |
| 51 | } |
| 52 | |