[llvm-bugs] [Bug 33727] New: std::basic_stringbuf only works with DefaultConstructible allocators

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Jul 10 07:12:25 PDT 2017


            Bug ID: 33727
           Summary: std::basic_stringbuf only works with
                    DefaultConstructible allocators
           Product: libc++
           Version: 4.0
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: zilla at kayari.org
                CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com

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>,

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.

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170710/6b75a6c8/attachment.html>

More information about the llvm-bugs mailing list