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 
20*7fc6a556SMarshall Clow #include "test_macros.h"
21*7fc6a556SMarshall 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>; };
264f4fc2eaSMarshall Clow   NoDefaultAllocator(int id_) : id(id_) { }
27a054f828SMarshall Clow   template<typename U> NoDefaultAllocator(const NoDefaultAllocator<U>& a) : id(a.id) { }
28a054f828SMarshall Clow   int id;
29a054f828SMarshall Clow };
30a054f828SMarshall Clow 
31a054f828SMarshall Clow 
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     }
475a83710eSEric Fiselier     {
485a83710eSEric Fiselier         std::wstringstream ss(L" 123 456 ");
495a83710eSEric Fiselier         assert(ss.rdbuf() != 0);
505a83710eSEric Fiselier         assert(ss.good());
515a83710eSEric Fiselier         assert(ss.str() == L" 123 456 ");
525a83710eSEric Fiselier         int i = 0;
535a83710eSEric Fiselier         ss >> i;
545a83710eSEric Fiselier         assert(i == 123);
555a83710eSEric Fiselier         ss >> i;
565a83710eSEric Fiselier         assert(i == 456);
575a83710eSEric Fiselier         ss << i << ' ' << 123;
585a83710eSEric Fiselier         assert(ss.str() == L"456 1236 ");
595a83710eSEric Fiselier     }
60a054f828SMarshall Clow     { // This is https://bugs.llvm.org/show_bug.cgi?id=33727
61a054f828SMarshall Clow         typedef std::basic_string   <char, std::char_traits<char>, NoDefaultAllocator<char> > S;
62a054f828SMarshall Clow         typedef std::basic_stringbuf<char, std::char_traits<char>, NoDefaultAllocator<char> > SB;
63a054f828SMarshall Clow 
64a054f828SMarshall Clow         S s(NoDefaultAllocator<char>(1));
65a054f828SMarshall Clow         SB sb(s);
66a054f828SMarshall Clow     //  This test is not required by the standard, but *where else* could it get the allocator?
67a054f828SMarshall Clow         assert(sb.str().get_allocator() == s.get_allocator());
68a054f828SMarshall Clow     }
692df59c50SJF Bastien 
702df59c50SJF Bastien   return 0;
715a83710eSEric Fiselier }
72