3 ms·
The 'visible union' rule is generally understood as meaning that the union type must be part of the access expression. Any other interpretation that only requir
by gpderetta 10y ago
The 'visible union' rule is generally understood as meaning that the union type must be part of the access expression. Any other interpretation that only requires the union to be in scope would pretty much render TBAA moot for any non trivial program.
And yes, this rule is part of the reason the current TBAA rules are such a mess. There is an outstanding C issue to clarify the wording here but the C commitee is severely under capacity.
There are proposed C++ wordings that clarify this rule in addition to generally clarify lifetimes and TBAA (while still being far from settling the issue, mind you). These wordings also introduce std::launder(), a function that bless some of the type punning tricks by explicitly informing the compiler about what's going on.
- kazinator 10y ago> Any other interpretation that only requires the union to be in scope would pretty much render TBAA moot for any non trivial program. An interpretation of the 'visible union' rule as being in scope is the only interpretation which doesn't render that text completely unnecessary. Of course if the access is taking place through the union, the union must be completely declared! When would you be able to access a union member as u.x, or pu->x, when the type of u or *pu is incomplete?