Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The postconditions required for copy assignment are specified by the C++ Standard, [utility.arg.requirements], Table 23 [ISO/IEC 14882-2014], which states that for x = y, the value of y is unchanged. When &x == &y, this postcondition translates into the values of both x and y remaining unchanged. A naive implementation of copy assignment will destroy object-local resources in the process of copying resources from the given parameter. If the given parameter is the same object as the local object, the act of destroying object-local resources will invalidate them. The subsequent copy of those resources will be left in an indeterminate state, which violates the postcondition.

...

The postconditions required for a move assignment are specified by the C++ Standard, [utility.arg.requirements], Table 22 [ISO/IEC 14882-2014], which states that for x = std::move(y), the value of y is left in a valid but unspecified state. When &x == &y, this postcondition translates into the values of both x and y remaining in a valid but unspecified state. Leaving the values in an unspecified state may result in vulnerabilities leading to exploitable code.

...

[Henricson 97]Rule 5.12, Copy assignment operators should be protected from doing destructive actions if an object is assigned to itself
[ISO/IEC 14882-2014]Subclause 17.6.3.1, "Template Argument Requirements"
Subclause 17.6.4.9, "Function Arguments"
[Meyers 05]Item 11, "Handle Assignment to Self in operator="
[Meyers 14] 

...