brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · 0aa7e1a Raw
57 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// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS -D_LIBCPP_ENABLE_CXX26_REMOVED_STRSTREAM10 11// <strstream>12 13// class strstreambuf14 15// strstreambuf(void* (*palloc_arg)(size_t), void (*pfree_arg)(void*));16 17#include <strstream>18#include <cassert>19 20#include "test_macros.h"21 22int called = 0;23 24void* my_alloc(std::size_t)25{26    static char buf[10000];27    ++called;28    return buf;29}30 31void my_free(void*)32{33    ++called;34}35 36struct test37    : std::strstreambuf38{39    test(void* (*palloc_arg)(std::size_t), void (*pfree_arg)(void*))40        : std::strstreambuf(palloc_arg, pfree_arg) {}41    virtual int_type overflow(int_type c)42        {return std::strstreambuf::overflow(c);}43};44 45int main(int, char**)46{47    {48        test s(my_alloc, my_free);49        assert(called == 0);50        s.overflow('a');51        assert(called == 1);52    }53    assert(called == 2);54 55  return 0;56}57