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// REQUIRES: has-unix-headers
10// UNSUPPORTED: libcpp-hardening-mode=none
11// XFAIL: libcpp-hardening-mode=debug && availability-verbose_abort-missing
12
13// <streambuf>
14
15// template <class charT, class traits = char_traits<charT> >
16// class basic_streambuf;
17
18// void setp(char_type* pbeg, char_type* pend);
19
20#include <algorithm>
21#include <iterator>
22#include <streambuf>
23#include <string>
24
25#include "check_assertion.h"
26#include "make_string.h"
27#include "test_macros.h"
28
29template <class CharT>
30struct streambuf : public std::basic_streambuf<CharT> {
31 typedef std::basic_streambuf<CharT> base;
32
33 streambuf() {}
34
35 void setp(CharT* pbeg, CharT* pend) { base::setp(pbeg, pend); }
36};
37
38template <class CharT>
39void test() {
40 std::basic_string<CharT> str = MAKE_STRING(CharT, "ABCDEF");
41 CharT arr[6];
42 std::copy(str.begin(), str.end(), arr);
43
44 {
45 streambuf<CharT> buff;
46 TEST_LIBCPP_ASSERT_FAILURE(buff.setp(std::begin(arr) + 3, std::begin(arr)), "[pbeg, pend) must be a valid range");
47 }
48}
49
50int main(int, char**) {
51 test<char>();
52#ifndef TEST_HAS_NO_WIDE_CHARACTERS
53 test<wchar_t>();
54#endif
55
56 return 0;
57}
58

source code of libcxx/test/std/input.output/stream.buffers/streambuf/streambuf.protected/streambuf.put.area/setp.assert.pass.cpp