The 2 print statements print different numbers. As far as I can see I'm not doing any dodgy const_cast
here so I'm not sure what UB I could have possibly committed.
Is this code well-formed?
Can the compiler rely on the fact that
A::num
isconst
so it's allowed to print the same number ?
Code:
struct A
{
const int num = 100;
A() {}
A(int in) : num{in} {}
void call()
{
new (this) A{69};
}
};
int main()
{
A a;
std::cout << a.num << '\n';
a.call();
std::cout << a.num << '\n';
}