Opened 7 years ago

Closed 7 years ago

#11786 closed Bugs (fixed)

Shouldn't boost::container::vector handle self-move-assignment?

Reported by: fredrik.astrom89@… Owned by: Ion Gaztañaga
Milestone: To Be Determined Component: container
Version: Boost 1.59.0 Severity: Problem
Keywords: Cc:

Description

Right now boost::container::vector disallows self-move-assignment. Looking at this seems to have been done by mistake. The code in question(taken from the function priv_move_assign in boost/container/vector.hpp) says:

//for move constructor, no aliasing (&x != this) is assummed.
BOOST_ASSERT(this != &x); 

(where x is the parameter)

As this isn't a move constructor I can only assume this is a mistake. If it isn't a mistake, just a bad comment, then I'd still argue that this should be changed. Mostly because VS2015 implementation of std::stable_partition assumes that self-move-assignment works...

Change History (1)

comment:1 by Ion Gaztañaga, 7 years ago

Resolution: fixed
Status: newclosed

Thanks for the report. It's an error in the comment as self assignment is not allowed for move assignments:

http://en.cppreference.com/w/cpp/utility/move

"Also, the standard library functions called with xvalue arguments may assume the argument is the only reference to the object; if it was constructed from an lvalue with std::move, no aliasing checks are made. In particular, this means that standard library move assignment operators do not have to perform self-assignment checks"

std::vector<int> v = {2, 3, 3};
v = std::move(v); // undefined behavior

Comment changed in commit https://github.com/boostorg/container/commit/08e768f1d89289f0783b5bab9ea9f2eb0753ed70

Note: See TracTickets for help on using tickets.