[ub] type punning through congruent base class?
Jason Merrill
jason at redhat.com
Mon Jan 6 19:22:24 CET 2014
On 01/06/2014 04:26 AM, Fabio Fracassi wrote:
> if it is not (legal): could we make it legal or would we run afoul of
> the aliasing rules?
The access is not allowed by the aliasing rules in 3.10. But it seems
that this would be:
struct B {
int i;
};
struct D {
B bmem;
void foo() { /* access bmem.i */ }
};
B b;
reinterpret_cast<D&>(b).foo();
because B is a non-static data member of D, and 9.2/19 guarantees that
the address of D::bmem is the same as the address of the D object.
Jason
More information about the ub
mailing list