C++ Logo

SG12

Advanced search

Subject: Re: [ub] type punning through congruent base class?
From: Jason Merrill (jason_at_[hidden])
Date: 2014-01-06 12:22:24


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


SG12 list run by herb.sutter at gmail.com