what is return type of 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

Placement new and assignment of class with const member

There is nothing that makes the shown code snippet inherently UB. However, it is almost certain UB will follow immediately under any normal usage. From [basic.life]/8 (emphasis mine) If, after the lifetime of an object has ended and before the storage which the object occupied is reused or released, a new object is created at … Read more

Why cannot a non-member function be used for overloading the assignment operator?

Firstly, it should be noted that this has nothing to do with the operator being implemented as a friend specifically. It is really about implementing the copy-assignment as a member function or as a non-member (standalone) function. Whether that standalone function is going to be a friend or not is completely irrelevant: it might be, … Read more