Page MenuHomePhabricator

[Sema][ObjC] Disallow non-trivial C struct fields in unions
Needs ReviewPublic

Authored by ahatanak on Dec 13 2018, 9:32 AM.

Details

Reviewers
rjmccall
Summary

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

Diff Detail

Repository
rC Clang

Event Timeline

ahatanak created this revision.Dec 13 2018, 9:32 AM

Just to clarify, this patch doesn't change clang's handling of C++ unions that have non-static data members with non-trivial special member functions.