What is the return type of the built-in assignment operator?

The standard correctly defines the return type of an assignment operator. Actually, the assignment operation itself doesn’t depend on the return value – that’s why the return type isn’t straightforward to understanding. The return type is important for chaining operations. Consider the following construction: a = b = c;. This should be equal to a …

Read more

const member and assignment operator. How to avoid the undefined behavior?

Your code causes undefined behavior. Not just “undefined if A is used as a base class and this, that or the other”. Actually undefined, always. return *this is already UB, because this is not guaranteed to refer to the new object. Specifically, consider 3.8/7: If, after the lifetime of an object has ended and before …

Read more

What is wrong with “checking for self-assignment” and what does it mean?

A question that’s of greater importance in this case would be: “What does it mean, when a you write function in a way, that requires you to check for self assignment???” To answer my rhetorical question: It means that a well-designed assignment operator should not need to check for self-assignment. Assigning an object to itself …

Read more

The forgotten assignment operator “=” and the commonplace “:=”

In PL/PgSQL parser, assignment operator is defined as assign_operator : ‘=’ | COLON_EQUALS ; This is a legacy feature, present in source code since 1998, when it was introduced – as we can see in the PostgreSQL Git repo. Starting from version 9.4 it is oficially documented. This idiosyncrasy – of having two operators for …

Read more

What does an ampersand after this assignment operator mean?

It’s part of a feature allowing C++11 non-static member functions to differentiate between whether they are being called on an lvalues or rvalues. In the above case, the copy assignment operator being defaulted here can only be called on lvalues. This uses the rules for lvalue and rvalue reference bindings that are well established; this …

Read more