brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.5 KiB · 6c74796 Raw
52 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// <streambuf>10 11// UNSUPPORTED: c++0312 13// template <class charT, class traits = char_traits<charT> >14// class basic_streambuf;15 16// void pbump(int n);17//18// REQUIRES: long_tests19 20// Unsupported for no-exceptions builds because they have no way to report an21// allocation failure when attempting to allocate the 2GiB string.22// UNSUPPORTED: no-exceptions23 24// Android devices frequently don't have enough memory to run this test. Rather25// than throw std::bad_alloc, exhausting memory triggers the OOM Killer.26// UNSUPPORTED: LIBCXX-ANDROID-FIXME27 28#include <sstream>29#include <cassert>30#include "test_macros.h"31 32struct SB : std::stringbuf33{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 39int main(int, char**)40{41    try {42        std::string str(2147483648, 'a');43        SB sb;44        sb.str(str);45        assert(sb.pubpbase() <= sb.pubpptr());46    }47    catch (const std::length_error &) {} // maybe the string can't take 2GB48    catch (const std::bad_alloc    &) {} // maybe we don't have enough RAM49 50  return 0;51}52