You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I understand the current version of the standard correctly the following code would not be UB (please correct me if I'm wrong):
#include<iostream>structC {
constint i;
voidf() const {
std::cout << i << "\n";
}
C(int i) : i(i) {}
C& operator=( const C& );
};
C& C::operator=( const C& other) {
if ( this != &other ) {
this->~C(); // lifetime of *this endsnew (this) C(other); // new object of type C createdf(); // well-defined
}
return *this;
}
intmain(){
C c1(1);
C c2(2);
c1 = c2; // well-defined
c1.f();
}
The important point is that with the new rules we allow the definition of a user defined assignment operator for non complete const objects with const sub-objects.
Could we mention this in a sample?
The text was updated successfully, but these errors were encountered:
bernd5
changed the title
Improve sample in [basic.life#8]
Improve / extend sample in [basic.life#8]
Aug 19, 2020
If I understand the current version of the standard correctly the following code would not be UB (please correct me if I'm wrong):
The important point is that with the new rules we allow the definition of a user defined assignment operator for non complete const objects with const sub-objects.
Could we mention this in a sample?
The text was updated successfully, but these errors were encountered: