Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std::basic_stringbuf only works with DefaultConstructible allocators #33074

Closed
jwakely mannequin opened this issue Jul 10, 2017 · 2 comments
Closed

std::basic_stringbuf only works with DefaultConstructible allocators #33074

jwakely mannequin opened this issue Jul 10, 2017 · 2 comments
Labels
bugzilla Issues migrated from bugzilla libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Comments

@jwakely
Copy link
Mannequin

jwakely mannequin commented Jul 10, 2017

Bugzilla Link 33727
Resolution FIXED
Resolved on Aug 02, 2017 10:31
Version 4.0
OS All
CC @mclow

Extended Description

This doesn't compile:

#include
#include
#include

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

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

int main()
{
string s(Alloc(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.

@jwakely
Copy link
Mannequin Author

jwakely mannequin commented Jul 10, 2017

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.

@mclow
Copy link
Contributor

mclow commented Aug 2, 2017

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?

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

No branches or pull requests

1 participant