This patch fixes a bug where clang doesn’t reject union fields of non-trivial struct types:
struct S0 { id x; }; struct S1 { id y; }; union U0 { struct S0 s0; // no diagnostics. struct S1 s1; // no diagnostics. }; union U1 { id x; // clang rejects ObjC pointer fields in unions. }; void test(union U0 a) { // Both ‘S0::x’ and ‘S1::y' are destructed in the IR. }
rdar://problem/46677858
Might be good to spell this out: we don't want to apply the C restriction in C++ because C++ (1) can apply the restriction at a finer grain by banning copying/destroying the union and (2) allows users to override these restrictions by declaring explicit constructors/etc., which we're not proposing to add to C.