LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 33727 - std::basic_stringbuf only works with DefaultConstructible allocators
Summary: std::basic_stringbuf only works with DefaultConstructible allocators
Status: RESOLVED FIXED
Alias: None
Product: libc++
Classification: Unclassified
Component: All Bugs (show other bugs)
Version: 4.0
Hardware: All All
: P normal
Assignee: Unassigned Clang Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-07-10 07:12 PDT by Jonathan Wakely
Modified: 2017-08-02 10:31 PDT (History)
2 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Wakely 2017-07-10 07:12:25 PDT
This doesn't compile:

#include <memory>
#include <sstream>
#include <cassert>

template<typename T>
struct Alloc : std::allocator<T>
{
  template<typename U> struct rebind { using other = Alloc<U>; };
  Alloc(int id) : id(id) { }
  template<typename U> Alloc(const Alloc<U>& a) : id(a.id) { }
  int id;
};

using string = std::basic_string<char, std::char_traits<char>, Alloc<char>>;
using stringbuf = std::basic_stringbuf<char, std::char_traits<char>, Alloc<char>>;

int main()
{
  string s(Alloc<char>(1));
  stringbuf b(s);
  assert( b.str().get_allocator() == s.get_allocator() );
}

The basic_stringbuf constructor default-initializes its basic_string member, which default-initializes its allocator.
Comment 1 Jonathan Wakely 2017-07-10 07:45:52 PDT
I'm planning to change libstdc++ so that basic_stringbuf(const basic_string&, ios_base::mode) calls get_allocator() on the string parameter for its internal string member. I don't plan to allow changing the allocator after construction.

That seems to be the easiest behaviour to explain, and also to implement.
Comment 2 Marshall Clow (home) 2017-08-02 10:31:32 PDT
> That seems to be the easiest behaviour to explain, and also to implement.

Yep. Simple and makes sense.
Fixed in revision 309838.

It would be nice to *say* that in the standard, too ;-)
Do you want to file an LWG issue?