Section: 16 [library] Status: NAD Submitter: Niels Dekker Opened: 2008-12-18 Last modified: 2016-01-28
Priority: Not Prioritized
View other active issues in [library].
View all other issues in [library].
View all issues with NAD status.
Discussion:
The assignment and equality operators =
and ==
are easily confused, just
because of their visual similarity, and in this case a simple typo can cause
a serious bug. When the left side of an operator=
is an rvalue, it's
highly unlikely that the assignment was intended by the programmer:
if ( func() = value ) // Typical typo: == intended!
Built-in types don't support assignment to an rvalue, but unfortunately, a lot of types provided by the Standard Library do.
Fortunately the language now offers a syntax to prevent a certain member
function from having an rvalue as *this
: by adding a ref-qualifier (&
)
to the member function declaration. Assignment operators are explicitly
mentioned as a use case of ref-qualifiers, in "Extending Move Semantics
To *this
(Revision 1)",
N1821 by Daveed
Vandevoorde and Bronek Kozicki
Hereby I would like to propose adding ref-qualifiers to all appropriate assignment operators in the library.
[ Batavia (2009-05): ]
Move to Open. We recommend this be deferred until after the next Committee Draft.
[ Frankfurt 2009-07: ]
The LWG declined to move forward with N2819.
Moved to NAD.
Proposed resolution:
A proposed resolution is provided by the paper on this subject, N2819, Ref-qualifiers for assignment operators of the Standard Library