Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -1003,10 +1003,11 @@ static Member *struct_designator(Token **rest, Token *tok, Type *ty) {

for (Member *mem = ty->members; mem; mem = mem->next) {
// Anonymous struct member
if (mem->ty->kind == TY_STRUCT && !mem->name) {
if (get_struct_member(mem->ty, tok)) {
*rest = start;
return mem;
if (!mem->name) {
if ((mem->ty->kind == TY_STRUCT || mem->ty->kind == TY_UNION)
&& get_struct_member(mem->ty, tok)) {
*rest = start;
return mem;
}
continue;
}
Expand Down Expand Up @@ -2736,11 +2737,13 @@ static Type *union_decl(Token **rest, Token *tok) {

// Find a struct member by name.
static Member *get_struct_member(Type *ty, Token *tok) {
assert(ty->kind == TY_STRUCT || ty->kind == TY_UNION);

for (Member *mem = ty->members; mem; mem = mem->next) {
// Anonymous struct member
if ((mem->ty->kind == TY_STRUCT || mem->ty->kind == TY_UNION) &&
!mem->name) {
if (get_struct_member(mem->ty, tok))
if (!mem->name) {
if ((mem->ty->kind == TY_STRUCT || mem->ty->kind == TY_UNION) &&
get_struct_member(mem->ty, tok))
return mem;
continue;
}
Expand Down
20 changes: 20 additions & 0 deletions test/anon-union-init.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "test.h"

struct foo {
int simple;
int : 7;
union {
int anon;
union tagged {
float qux;
long baz;
} named;
};
};

struct foo bar = { .simple = 1, .named.qux = 1.0 };

int main() {
printf("OK\n");
return 0;
}