From 3e56584223a67a6c2f41a43cf38e0960e9992238 Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Mon, 31 Mar 2014 22:58:17 +0800 Subject: [PATCH] Allow local redefinition of enumerator --- tccgen.c | 2 +- tests/tests2/63_local_enumerator_redefinition.c | 14 ++++++++++++++ .../tests2/63_local_enumerator_redefinition.expect | 0 tests/tests2/Makefile | 3 ++- 4 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 tests/tests2/63_local_enumerator_redefinition.c create mode 100644 tests/tests2/63_local_enumerator_redefinition.expect diff --git a/tccgen.c b/tccgen.c index 31717202..84188ad3 100644 --- a/tccgen.c +++ b/tccgen.c @@ -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(); diff --git a/tests/tests2/63_local_enumerator_redefinition.c b/tests/tests2/63_local_enumerator_redefinition.c new file mode 100644 index 00000000..dd4d8e05 --- /dev/null +++ b/tests/tests2/63_local_enumerator_redefinition.c @@ -0,0 +1,14 @@ +enum { + FOO, + BAR +}; + +int main(void) +{ + enum { + FOO = 2, + BAR + }; + + return BAR - FOO; +} diff --git a/tests/tests2/63_local_enumerator_redefinition.expect b/tests/tests2/63_local_enumerator_redefinition.expect new file mode 100644 index 00000000..e69de29b diff --git a/tests/tests2/Makefile b/tests/tests2/Makefile index fa564f93..bd6f2c1d 100644 --- a/tests/tests2/Makefile +++ b/tests/tests2/Makefile @@ -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