While working on fixing PR30520 yesterday I noticed that clang also crashes on code like this:
template<typename T> union u { T b; } __attribute__((transparent_union));
I mentioned in https://reviews.llvm.org/D25273 that I plan on fixing it properly by instantiating the attribute, but, after looking more into it, I discovered that we don't really support 'transparent_union' in C++ at all. This is why I decided to go with the approach that's presented in this patch: the attribute is completely ignored when clang is in C++ mode, and thus the crash is avoided.
I wasn't sure if we should we emit an error or a warning when ignoring this attribute and if we need any diagnostics in Gnu mode at all. That's why in this initial patch doesn't emit a diagnostic when ignoring this attribute. Please let me know whether we need to show one or not.
Thanks
The correct way to do this is to mark the attribute as C-only on its declaration in Attr.td. See the definition of FlagEnum for an example.