Allow local redefinition of enumerator

master
Thomas Preud'homme 2014-03-31 22:58:17 +08:00
parent a620b12dc1
commit 3e56584223
4 changed files with 17 additions and 2 deletions

View File

@ -2827,7 +2827,7 @@ static void struct_decl(CType *type, int u, int tdef)
if (v < TOK_UIDENT)
expect("identifier");
ss = sym_find(v);
if (ss)
if (ss && !local_stack)
tcc_error("redefinition of enumerator '%s'",
get_tok_str(v, NULL));
next();

View File

@ -0,0 +1,14 @@
enum {
FOO,
BAR
};
int main(void)
{
enum {
FOO = 2,
BAR
};
return BAR - FOO;
}

View File

@ -74,7 +74,8 @@ TESTS = \
59_function_array.test \
60_enum_redefinition.test \
61_undefined_enum.test \
62_enumerator_redefinition.test
62_enumerator_redefinition.test \
63_local_enumerator_redefinition.test
# 30_hanoi.test -- seg fault in the code, gcc as well
# 34_array_assignment.test -- array assignment is not in C standard