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 // <sstream>
10 
11 // template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
12 // class basic_ostringstream
13 
14 // explicit basic_ostringstream(ios_base::openmode which = ios_base::out); // before C++20
15 // basic_ostringstream() : basic_ostringstream(ios_base::out) {}           // C++20
16 // explicit basic_ostringstream(ios_base::openmode which);                 // C++20
17 
18 // XFAIL: FROZEN-CXX03-HEADERS-FIXME
19 
20 #include <sstream>
21 #include <cassert>
22 
23 #include "operator_hijacker.h"
24 #include "test_macros.h"
25 #if TEST_STD_VER >= 11
26 #include "test_convertible.h"
27 
28 template <typename S>
29 void test() {
30   static_assert(test_convertible<S>(), "");
31   static_assert(!test_convertible<S, std::ios_base::openmode>(), "");
32 }
33 #endif
34 
35 int main(int, char**)
36 {
37     {
38         std::ostringstream ss;
39         assert(ss.rdbuf() != nullptr);
40         assert(ss.good());
41         assert(ss.str() == "");
42     }
43     {
44       std::basic_ostringstream<char, std::char_traits<char>, operator_hijacker_allocator<char> > ss;
45       assert(ss.rdbuf() != nullptr);
46       assert(ss.good());
47       assert(ss.str() == "");
48     }
49     {
50         std::ostringstream ss(std::ios_base::out);
51         assert(ss.rdbuf() != nullptr);
52         assert(ss.good());
53         assert(ss.str() == "");
54     }
55     {
56       std::basic_ostringstream<char, std::char_traits<char>, operator_hijacker_allocator<char> > ss(std::ios_base::out);
57       assert(ss.rdbuf() != nullptr);
58       assert(ss.good());
59       assert(ss.str() == "");
60     }
61 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
62     {
63         std::wostringstream ss;
64         assert(ss.rdbuf() != nullptr);
65         assert(ss.good());
66         assert(ss.str() == L"");
67     }
68     {
69       std::basic_ostringstream<wchar_t, std::char_traits<wchar_t>, operator_hijacker_allocator<wchar_t> > ss;
70       assert(ss.rdbuf() != nullptr);
71       assert(ss.good());
72       assert(ss.str() == L"");
73     }
74     {
75         std::wostringstream ss(std::ios_base::out);
76         assert(ss.rdbuf() != nullptr);
77         assert(ss.good());
78         assert(ss.str() == L"");
79     }
80     {
81       std::basic_ostringstream<wchar_t, std::char_traits<wchar_t>, operator_hijacker_allocator<wchar_t> > ss(
82           std::ios_base::out);
83       assert(ss.rdbuf() != nullptr);
84       assert(ss.good());
85       assert(ss.str() == L"");
86     }
87 #endif // TEST_HAS_NO_WIDE_CHARACTERS
88 
89 #if TEST_STD_VER >= 11
90     test<std::ostringstream>();
91 #  ifndef TEST_HAS_NO_WIDE_CHARACTERS
92     test<std::wostringstream>();
93 #   endif
94 #endif
95 
96     return 0;
97 }
98