Clang compiles with error following test case
typedef union attribute((transparent_union)) {
int *i; struct st *s;
} TU;
void bar(TU);
void foo(int *i) {
bar(i);
}
clang -c tu.c
tu.c:1:30: warning: transparent_union attribute can only be applied to a union definition; attribute ignored [-Wignored-attributes]
typedef union attribute((transparent_union)) {
^
tu.c:8:24: error: passing 'int *' to parameter of incompatible type 'TU'
void foo(int *i) { bar(i); }
^
tu.c:6:12: note: passing argument to parameter here
void bar(TU);
^
GCC compiles this test successfully.
The compilation is failed because the routine handleTransparentUnionAttr requires for the record decl to be completed. This fix provides handling of the attribute ‘transparent_union’ after parsing of union.
This does not seem like a particularly clean way to solve this problem. It's a bit strange for some part of the semantics engine to claim a declaration is currently being parsed, and it's fragile that the only way to set that it is no longer being parsed is when processing the attribute list.