boostorg / container

STL-like containers from Boost
http://www.boost.org/libs/container/
Boost Software License 1.0
100 stars 116 forks source link

Implement C++17 MoveAssignable requirements for self-move assignments #88

Closed igaztanaga closed 5 years ago

igaztanaga commented 5 years ago

In C++17, self-move assignment is no longer undefined behavior:

MoveAssignable requirements [moveassignable]

[ Note: rv must still meet the requirements of the library component that is using it, whether or not t and rv refer to the same object. The operations listed in those requirements must work as specified whether rv has been moved from or not. — end note ]

All Boost.Container classes should be updated to guarantee MoveAssignable requirements

Mike-Devel commented 5 years ago

Are you sure that self move is allowed/required to work in c++17? That would be a breaking change. Can you post a link to the section?

igaztanaga commented 5 years ago

According to the final draft before C++17 (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4659.pdf):

Section 20.5.3.1, Table 25 — MoveAssignable requirements [moveassignable]

Expression: t = rv Return type: T& Return value: t Post-condition: If t and rv do not refer to the same object, t is equivalent to the value of rv before the assignment rv’s state is unspecified. [ Note: rv must still meet the requirements of the library component that is using it, whether or not t and rv refer to the same object. The operations listed in those requirements must work as specified whether rv has been moved from or not. — end note ]

Mike-Devel commented 5 years ago

I guess you are right. I read this as "even after self move assignment the object must still be in a valid state" (even if it isn't specified what that state is exactly).

faithandbrave commented 5 years ago

FYI : https://wg21.cmeerw.net/lwg/issue2468

linholmes commented 4 years ago

Will it influence the old C++ version of compiler,just like c++14 or c++11?