For example:
const int* pc = new const int(3); // note the const
int* p = const_cast<int*>(pc);
*p = 4; // undefined behavior?
In particular, can the compiler ever optimize away the heap-allocated *pc
?
If not, does an attempt to modify *pc
via p
still constitute undefined behavior - and if so, why?