1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
11 // template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
12 // class basic_stringstream
14 // explicit basic_stringstream(const basic_string<charT,traits,Allocator>& str,
15 // ios_base::openmode which = ios_base::out|ios_base::in);
17 // XFAIL: FROZEN-CXX03-HEADERS-FIXME
22 #include "test_macros.h"
23 #include "operator_hijacker.h"
26 struct NoDefaultAllocator
: std::allocator
<T
>
28 template<typename U
> struct rebind
{ using other
= NoDefaultAllocator
<U
>; };
29 NoDefaultAllocator(int id_
) : id(id_
) { }
30 template<typename U
> NoDefaultAllocator(const NoDefaultAllocator
<U
>& a
) : id(a
.id
) { }
38 std::stringstream
ss(" 123 456 ");
39 assert(ss
.rdbuf() != nullptr);
41 assert(ss
.str() == " 123 456 ");
47 ss
<< i
<< ' ' << 123;
48 assert(ss
.str() == "456 1236 ");
51 std::basic_stringstream
<char, std::char_traits
<char>, operator_hijacker_allocator
<char> > ss(" 123 456 ");
52 assert(ss
.rdbuf() != nullptr);
54 assert(ss
.str() == " 123 456 ");
60 ss
<< i
<< ' ' << 123;
61 assert(ss
.str() == "456 1236 ");
63 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
65 std::wstringstream
ss(L
" 123 456 ");
66 assert(ss
.rdbuf() != nullptr);
68 assert(ss
.str() == L
" 123 456 ");
74 ss
<< i
<< ' ' << 123;
75 assert(ss
.str() == L
"456 1236 ");
78 std::basic_stringstream
<wchar_t, std::char_traits
<wchar_t>, operator_hijacker_allocator
<wchar_t> > ss(
80 assert(ss
.rdbuf() != nullptr);
82 assert(ss
.str() == L
" 123 456 ");
88 ss
<< i
<< ' ' << 123;
89 assert(ss
.str() == L
"456 1236 ");
92 { // This is https://llvm.org/PR33727
93 typedef std::basic_string
<char, std::char_traits
<char>, NoDefaultAllocator
<char> > S
;
94 typedef std::basic_stringbuf
<char, std::char_traits
<char>, NoDefaultAllocator
<char> > SB
;
96 S
s(NoDefaultAllocator
<char>(1));
98 // This test is not required by the standard, but *where else* could it get the allocator?
99 assert(sb
.str().get_allocator() == s
.get_allocator());