I was wondering what the security standard says for the following code:
class A { int v; }; class B: public A { };
Obviously, the execution type is a - a , not B , so overlapping is not type safe. However, since no member was added, and nothing was virtual, IMO, the class memory layout should be the same and this should work (maybe it would be better to write reinterpret_cast to indicate this behavior?). I assume this is UB, but will work with any compiler. Or is it really well defined? Or is it quite dangerous?
Also, would anything change if B had some additional non-virtual member methods? Again, intuitively, I would say no, but I wonder what the standard has to say about it.
source share