Fix self-referenced enum declarations

eg:
typedef enum foo {
    bar = 1,
    baz = bar,
} foo;
This commit is contained in:
Bill Currie 2020-02-19 01:28:09 +09:00
parent ed283a9e7f
commit ee228504aa
2 changed files with 3 additions and 0 deletions

View file

@ -553,6 +553,7 @@ optional_enum_list
enum_list
: '{' enum_init enumerator_list optional_comma '}'
{
current_symtab = current_symtab->parent;
$$ = finish_enum ($3);
}
;
@ -562,6 +563,7 @@ enum_init
{
$$ = find_enum ($<symbol>-1);
start_enum ($$);
current_symtab = $$->type->t.symtab;
}
;

View file

@ -201,6 +201,7 @@ add_enum (symbol_t *enm, symbol_t *name, expr_t *val)
if (enum_tab->symbols)
value = ((symbol_t *)(enum_tab->symtail))->s.value->v.integer_val + 1;
if (val) {
convert_name (val);
if (!is_constant (val))
error (val, "non-constant initializer");
else if (!is_integer_val (val))