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_stringstream 13 14 // explicit basic_stringstream(ios_base::openmode which = ios_base::out | ios_base::in); // before C++20 15 // basic_stringstream() : basic_stringstream(ios_base::out | ios_base::in) {} // C++20 16 // explicit basic_stringstream(ios_base::openmode which); // C++20 17 18 // XFAIL: FROZEN-CXX03-HEADERS-FIXME 19 20 #include <sstream> 21 #include <cassert> 22 23 #include "test_macros.h" 24 #include "operator_hijacker.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::stringstream ss; 39 assert(ss.rdbuf() != nullptr); 40 assert(ss.good()); 41 assert(ss.str() == ""); 42 } 43 { 44 std::basic_stringstream<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::stringstream ss(std::ios_base::in); 51 assert(ss.rdbuf() != nullptr); 52 assert(ss.good()); 53 assert(ss.str() == ""); 54 } 55 { 56 std::basic_stringstream<char, std::char_traits<char>, operator_hijacker_allocator<char> > ss(std::ios_base::in); 57 assert(ss.rdbuf() != nullptr); 58 assert(ss.good()); 59 assert(ss.str() == ""); 60 } 61 #ifndef TEST_HAS_NO_WIDE_CHARACTERS 62 { 63 std::wstringstream ss; 64 assert(ss.rdbuf() != nullptr); 65 assert(ss.good()); 66 assert(ss.str() == L""); 67 } 68 { 69 std::wstringstream ss(std::ios_base::in); 70 assert(ss.rdbuf() != nullptr); 71 assert(ss.good()); 72 assert(ss.str() == L""); 73 } 74 #endif 75 76 #if TEST_STD_VER >= 11 77 test<std::stringstream>(); 78 # ifndef TEST_HAS_NO_WIDE_CHARACTERS 79 test<std::wstringstream>(); 80 # endif 81 #endif 82 83 return 0; 84 } 85