rui314 / 8cc

A Small C Compiler
MIT License
6.12k stars 742 forks source link

Fix a parser bug in struct initialization. #65

Open gergo- opened 9 years ago

gergo- commented 9 years ago

When initializing a struct containing a struct via a variable (see test/initializer.c, function test_struct()):

struct foo { int a; int b; } f = { 1, 2 };
struct { struct foo f; } b = { f };

8cc failed with a type error: [ERROR] parse.c:617: (null): incompatible kind: <(struct (int) (int))>

The read_initializer_elem function did not expect an identifier as a valid struct member initializer. This patch seems to fix that (make fulltest passes with the above-mentioned test added).