Skip to content

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

@StephanTLavavej

Description

@StephanTLavavej

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixedSomething works now, yay!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions