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 #include <sstream>
19 #include <cassert>
20 
21 #include "test_macros.h"
22 #if TEST_STD_VER >= 11
23 #include "test_convertible.h"
24 
25 template <typename S>
26 void test() {
27   static_assert(test_convertible<S>(), "");
28   static_assert(!test_convertible<S, std::ios_base::openmode>(), "");
29 }
30 #endif
31 
32 int main(int, char**)
33 {
34     {
35         std::ostringstream ss;
36         assert(ss.rdbuf() != 0);
37         assert(ss.good());
38         assert(ss.str() == "");
39     }
40     {
41         std::ostringstream ss(std::ios_base::out);
42         assert(ss.rdbuf() != 0);
43         assert(ss.good());
44         assert(ss.str() == "");
45     }
46 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
47     {
48         std::wostringstream ss;
49         assert(ss.rdbuf() != 0);
50         assert(ss.good());
51         assert(ss.str() == L"");
52     }
53     {
54         std::wostringstream ss(std::ios_base::out);
55         assert(ss.rdbuf() != 0);
56         assert(ss.good());
57         assert(ss.str() == L"");
58     }
59 #endif // TEST_HAS_NO_WIDE_CHARACTERS
60 
61 #if TEST_STD_VER >= 11
62     test<std::ostringstream>();
63 #   ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
64     test<std::wostringstream>();
65 #   endif
66 #endif
67 
68     return 0;
69 }
70