Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Expanded explanation of how self-move assignment occurs in the wild.

...

The C++ Standard, [res.on.arguments], paragraph 1, specifies that function arguments that bind to rvalue reference parameters must be a unique reference to that parameter. Thus, the Standard Template Library does not gracefully handle self-move assignment, so such operations lead to undefined behavior. While this statement only normatively holds for objects passed as rvalue references into Standard Template Library functions, it is common practice to omit checks for self-move assignment within a move assignment operator [Meyers 14]. This is because An rvalue reference parameter logically denotes an object that is either a true temporary object, or an object the caller wishes to be treated as being temporary. When given a reference to an object that is a true temporary object, by definition that object is unique, and so self-move assignment is impossible. Because move assignment is an optimized form of copy assignment, and so performance concerns are generally treated with higher priority than security concerns. By removing a removing the check for self-move assignment , is reasonable performance advice because an extra branch (that would have been rarely should never be taken) can be removed from the implementation of the move assignment operator. However, because the caller is able to denote an object as being logically temporary, there exists the possibility of self-move assignment with security implications.

Noncompliant Code Example

...