From: Jonathan Wakely Date: Mon, 10 Jul 2017 17:59:02 +0000 (+0100) Subject: PR libstdc++/81381 support stateful allocators in basic_stringbuf X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=387c17d312f76173b9af2717cb89359e09647c28;p=gcc.git PR libstdc++/81381 support stateful allocators in basic_stringbuf PR libstdc++/81381 * include/bits/sstream.tcc (basic_stringbuf::overflow) (basic_stringbuf::basic_stringbuf(const __string_type&, ios::mode)) (basic_stringbuf::str()): Construct new strings with an allocator. * testsuite/27_io/basic_stringbuf/cons/81381.cc: New. From-SVN: r250101 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 58adb85608b..25e3aed5b0f 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,11 @@ 2017-07-10 Jonathan Wakely + PR libstdc++/81381 + * include/bits/sstream.tcc (basic_stringbuf::overflow) + (basic_stringbuf::basic_stringbuf(const __string_type&, ios::mode)) + (basic_stringbuf::str()): Construct new strings with an allocator. + * testsuite/27_io/basic_stringbuf/cons/81381.cc: New. + PR libstdc++/81338 * include/bits/basic_string.h [_GLIBCXX_USE_CXX11_ABI] (basic_string): Declare basic_stringbuf to be a friend. diff --git a/libstdc++-v3/include/bits/sstream.tcc b/libstdc++-v3/include/bits/sstream.tcc index fc2fcb8992d..56c53bc5923 100644 --- a/libstdc++-v3/include/bits/sstream.tcc +++ b/libstdc++-v3/include/bits/sstream.tcc @@ -129,7 +129,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION const __size_type __opt_len = std::max(__size_type(2 * __capacity), __size_type(512)); const __size_type __len = std::min(__opt_len, __max_size); - __string_type __tmp; + __string_type __tmp(_M_string.get_allocator()); __tmp.reserve(__len); if (this->pbase()) __tmp.assign(this->pbase(), this->epptr() - this->pbase()); diff --git a/libstdc++-v3/include/std/sstream b/libstdc++-v3/include/std/sstream index 7690252b3e3..e84b60c6417 100644 --- a/libstdc++-v3/include/std/sstream +++ b/libstdc++-v3/include/std/sstream @@ -112,7 +112,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 explicit basic_stringbuf(const __string_type& __str, ios_base::openmode __mode = ios_base::in | ios_base::out) - : __streambuf_type(), _M_mode(), _M_string(__str.data(), __str.size()) + : __streambuf_type(), _M_mode(), + _M_string(__str.data(), __str.size(), __str.get_allocator()) { _M_stringbuf_init(__mode); } #if __cplusplus >= 201103L @@ -165,14 +166,14 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 __string_type str() const { - __string_type __ret; + __string_type __ret(_M_string.get_allocator()); if (this->pptr()) { // The current egptr() may not be the actual string end. if (this->pptr() > this->egptr()) - __ret = __string_type(this->pbase(), this->pptr()); + __ret.assign(this->pbase(), this->pptr()); else - __ret = __string_type(this->pbase(), this->egptr()); + __ret.assign(this->pbase(), this->egptr()); } else __ret = _M_string; diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/81381.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/81381.cc new file mode 100644 index 00000000000..865449d72ee --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/81381.cc @@ -0,0 +1,42 @@ +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-do run { target c++11 } } + +// PR libstdc++/81381 + +#include +#include +#include + +using Alloc = __gnu_test::uneq_allocator; +using String = std::basic_string, Alloc>; + +struct SB : std::basic_stringbuf, Alloc> +{ + SB(const String& s) : basic_stringbuf(s) { } + + using basic_stringbuf::overflow; +}; + +int main() +{ + String s(Alloc(23)); + SB b(s); + b.overflow('a'); + VERIFY( b.str().get_allocator() == s.get_allocator() ); +}