15a83710eSEric Fiselier //===----------------------------------------------------------------------===//
25a83710eSEric Fiselier //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65a83710eSEric Fiselier //
75a83710eSEric Fiselier //===----------------------------------------------------------------------===//
85a83710eSEric Fiselier
95a83710eSEric Fiselier // <sstream>
105a83710eSEric Fiselier
115a83710eSEric Fiselier // template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
125a83710eSEric Fiselier // class basic_stringstream
135a83710eSEric Fiselier
145a83710eSEric Fiselier // explicit basic_stringstream(const basic_string<charT,traits,Allocator>& str,
155a83710eSEric Fiselier // ios_base::openmode which = ios_base::out|ios_base::in);
165a83710eSEric Fiselier
175a83710eSEric Fiselier #include <sstream>
185a83710eSEric Fiselier #include <cassert>
195a83710eSEric Fiselier
207fc6a556SMarshall Clow #include "test_macros.h"
217fc6a556SMarshall Clow
22a054f828SMarshall Clow template<typename T>
23a054f828SMarshall Clow struct NoDefaultAllocator : std::allocator<T>
24a054f828SMarshall Clow {
25a054f828SMarshall Clow template<typename U> struct rebind { using other = NoDefaultAllocator<U>; };
NoDefaultAllocatorNoDefaultAllocator264f4fc2eaSMarshall Clow NoDefaultAllocator(int id_) : id(id_) { }
NoDefaultAllocatorNoDefaultAllocator27a054f828SMarshall Clow template<typename U> NoDefaultAllocator(const NoDefaultAllocator<U>& a) : id(a.id) { }
28a054f828SMarshall Clow int id;
29a054f828SMarshall Clow };
30a054f828SMarshall Clow
31a054f828SMarshall Clow
main(int,char **)322df59c50SJF Bastien int main(int, char**)
335a83710eSEric Fiselier {
345a83710eSEric Fiselier {
355a83710eSEric Fiselier std::stringstream ss(" 123 456 ");
365a83710eSEric Fiselier assert(ss.rdbuf() != 0);
375a83710eSEric Fiselier assert(ss.good());
385a83710eSEric Fiselier assert(ss.str() == " 123 456 ");
395a83710eSEric Fiselier int i = 0;
405a83710eSEric Fiselier ss >> i;
415a83710eSEric Fiselier assert(i == 123);
425a83710eSEric Fiselier ss >> i;
435a83710eSEric Fiselier assert(i == 456);
445a83710eSEric Fiselier ss << i << ' ' << 123;
455a83710eSEric Fiselier assert(ss.str() == "456 1236 ");
465a83710eSEric Fiselier }
47*f4c1258dSLouis Dionne #ifndef TEST_HAS_NO_WIDE_CHARACTERS
485a83710eSEric Fiselier {
495a83710eSEric Fiselier std::wstringstream ss(L" 123 456 ");
505a83710eSEric Fiselier assert(ss.rdbuf() != 0);
515a83710eSEric Fiselier assert(ss.good());
525a83710eSEric Fiselier assert(ss.str() == L" 123 456 ");
535a83710eSEric Fiselier int i = 0;
545a83710eSEric Fiselier ss >> i;
555a83710eSEric Fiselier assert(i == 123);
565a83710eSEric Fiselier ss >> i;
575a83710eSEric Fiselier assert(i == 456);
585a83710eSEric Fiselier ss << i << ' ' << 123;
595a83710eSEric Fiselier assert(ss.str() == L"456 1236 ");
605a83710eSEric Fiselier }
61*f4c1258dSLouis Dionne #endif
623c62198cSLouis Dionne { // This is https://llvm.org/PR33727
63a054f828SMarshall Clow typedef std::basic_string <char, std::char_traits<char>, NoDefaultAllocator<char> > S;
64a054f828SMarshall Clow typedef std::basic_stringbuf<char, std::char_traits<char>, NoDefaultAllocator<char> > SB;
65a054f828SMarshall Clow
66a054f828SMarshall Clow S s(NoDefaultAllocator<char>(1));
67a054f828SMarshall Clow SB sb(s);
68a054f828SMarshall Clow // This test is not required by the standard, but *where else* could it get the allocator?
69a054f828SMarshall Clow assert(sb.str().get_allocator() == s.get_allocator());
70a054f828SMarshall Clow }
712df59c50SJF Bastien
722df59c50SJF Bastien return 0;
735a83710eSEric Fiselier }
74