This patch diagnoses uses of non-trivial C unions in the following contexts:
- function parameters
- function returns
- variables with automatic storage duration
- assignment
- compound literal with automatic storage duration
- block capture except when a __block variable is captured by a non-escaping block
Note that we already reject non-trivial C structs/unions used for variable function arguments. Also this patch doesn't detect non-trivial C unions passed to functions without function prototypes. I think that's okay since clang will reject the function definition's parameters, but if it isn't okay, it's possible to add diagnostics for that too.
See the discussion in https://reviews.llvm.org/D62988 for more background.
rdar://problem/50679094
You only want these checks to trigger on unions with non-trivial members (or structs containing them), right? How about something like hasNonTrivialPrimitiveCUnionMember()? Or maybe make it more descriptive for the use sites, like isPrimitiveCRestrictedType()?
Also, it would be nice if the fast path of this could be inlined so that clients usually didn't had to make a call at all. You can write the getBaseElementTypeUnsafe()->getAs<RecordType>() part in an inline implementation at the bottom this file.