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 setg(char_type* gbeg, char_type* gnext, char_type* gend);
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 
29 template <class CharT>
30 struct streambuf : public std::basic_streambuf<CharT> {
31   typedef std::basic_streambuf<CharT> base;
32 
streambufstreambuf33   streambuf() {}
34 
setgstreambuf35   void setg(CharT* gbeg, CharT* gnext, CharT* gend) { base::setg(gbeg, gnext, gend); }
36 };
37 
38 template <class CharT>
test()39 void 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(
47         buff.setg(std::begin(arr) + 1, std::begin(arr), std::end(arr)), "[gbeg, gnext) must be a valid range");
48   }
49   {
50     streambuf<CharT> buff;
51     TEST_LIBCPP_ASSERT_FAILURE(
52         buff.setg(std::begin(arr) + 1, std::begin(arr) + 1, std::begin(arr)), "[gbeg, gend) must be a valid range");
53   }
54   {
55     streambuf<CharT> buff;
56     TEST_LIBCPP_ASSERT_FAILURE(
57         buff.setg(std::begin(arr), std::begin(arr) + 3, std::begin(arr) + 2), "[gnext, gend) must be a valid range");
58   }
59 }
60 
main(int,char **)61 int main(int, char**) {
62   test<char>();
63 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
64   test<wchar_t>();
65 #endif
66 
67   return 0;
68 }
69