| 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 | // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS -D_LIBCPP_ENABLE_CXX26_REMOVED_STRSTREAM |
| 10 | |
| 11 | // <strstream> |
| 12 | |
| 13 | // class strstreambuf |
| 14 | |
| 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 | |
| 22 | int called = 0; |
| 23 | |
| 24 | void* my_alloc(std::size_t) |
| 25 | { |
| 26 | static char buf[10000]; |
| 27 | ++called; |
| 28 | return buf; |
| 29 | } |
| 30 | |
| 31 | void my_free(void*) |
| 32 | { |
| 33 | ++called; |
| 34 | } |
| 35 | |
| 36 | struct test |
| 37 | : std::strstreambuf |
| 38 | { |
| 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: c);} |
| 43 | }; |
| 44 | |
| 45 | int main(int, char**) |
| 46 | { |
| 47 | { |
| 48 | test s(my_alloc, my_free); |
| 49 | assert(called == 0); |
| 50 | s.overflow(c: 'a'); |
| 51 | assert(called == 1); |
| 52 | } |
| 53 | assert(called == 2); |
| 54 | |
| 55 | return 0; |
| 56 | } |
| 57 | |