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

<sstream>: basic_stringbuf shouldn't implement moving with swapping #4232

Closed
StephanTLavavej opened this issue Dec 3, 2023 · 0 comments · Fixed by #4239
Closed

<sstream>: basic_stringbuf shouldn't implement moving with swapping #4232

StephanTLavavej opened this issue Dec 3, 2023 · 0 comments · Fixed by #4239
Labels
bug Something isn't working fixed Something works now, yay!

Comments

@StephanTLavavej
Copy link
Member

basic_stringbuf implements move construction and move assignment with swap():

STL/stl/inc/sstream

Lines 74 to 88 in 0403d19

basic_stringbuf(basic_stringbuf&& _Right) : _Mystate(0) {
_Assign_rv(_STD move(_Right));
}
basic_stringbuf& operator=(basic_stringbuf&& _Right) noexcept /* strengthened */ {
_Assign_rv(_STD move(_Right));
return *this;
}
void _Assign_rv(basic_stringbuf&& _Right) noexcept {
if (this != _STD addressof(_Right)) {
_Tidy();
this->swap(_Right);
}
}

This is bogus because swap() activates POCS logic (propagate_on_container_swap), but move assignment needs to activate POCMA logic (propagate_on_container_move_assignment). The unconditional noexcept strengthening is also bogus.

Found by std/input.output/string.streams/stringbuf/stringbuf.cons/move.alloc.pass.cpp in the upcoming libcxx update that I'm working on. The error was sstream(94) : Assertion failed: The allocators of basic_stringbuf should propagate or be equal on swap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed Something works now, yay!
Projects
None yet
1 participant