diff --git a/tccgen.c b/tccgen.c
index 87ec798c..84d4e851 100644
--- a/tccgen.c
+++ b/tccgen.c
@@ -571,6 +571,14 @@ ST_INLN Sym *sym_find(int v)
     return table_ident[v]->sym_identifier;
 }
 
+static int sym_scope(Sym *s)
+{
+  if (IS_ENUM_VAL (s->type.t))
+    return s->type.ref->sym_scope;
+  else
+    return s->sym_scope;
+}
+
 /* push a given symbol on the symbol stack */
 ST_FUNC Sym *sym_push(int v, CType *type, int r, int c)
 {
@@ -596,7 +604,7 @@ ST_FUNC Sym *sym_push(int v, CType *type, int r, int c)
         s->prev_tok = *ps;
         *ps = s;
         s->sym_scope = local_scope;
-        if (s->prev_tok && s->prev_tok->sym_scope == s->sym_scope)
+        if (s->prev_tok && sym_scope(s->prev_tok) == s->sym_scope)
             tcc_error("redeclaration of '%s'",
                 get_tok_str(v & ~SYM_STRUCT, NULL));
     }
@@ -919,7 +927,7 @@ static void merge_attr(AttributeDef *ad, AttributeDef *ad1)
 /* Merge some type attributes.  */
 static void patch_type(Sym *sym, CType *type)
 {
-    if (!(type->t & VT_EXTERN)) {
+    if (!(type->t & VT_EXTERN) || IS_ENUM_VAL(sym->type.t)) {
         if (!(sym->type.t & VT_EXTERN))
             tcc_error("redefinition of '%s'", get_tok_str(sym->v, NULL));
         sym->type.t &= ~VT_EXTERN;
diff --git a/tests/tests2/60_errors_and_warnings.c b/tests/tests2/60_errors_and_warnings.c
index 289c0304..cefaf73f 100644
--- a/tests/tests2/60_errors_and_warnings.c
+++ b/tests/tests2/60_errors_and_warnings.c
@@ -124,4 +124,10 @@ void f() { _Generic((int const *[]){0}, int:0); }
 void f() { _Generic((int (*(*)(float,char))(double,int)){0}, int:0); }
 #elif defined test_array_to_str
 void f() { _Generic((int(*)[3]){0}, int:0); }
+#elif defined test_duplicate_def_1
+static enum myenum { L = -1 } L;                                                
+#elif defined test_duplicate_def_2
+void foo(void) {
+static enum myenum { L = -1 } L;                                                
+}
 #endif
diff --git a/tests/tests2/60_errors_and_warnings.expect b/tests/tests2/60_errors_and_warnings.expect
index aae5ce9e..eaad7b9e 100644
--- a/tests/tests2/60_errors_and_warnings.expect
+++ b/tests/tests2/60_errors_and_warnings.expect
@@ -53,3 +53,9 @@
 
 [test_array_to_str]
 60_errors_and_warnings.c:126: error: type 'int (*)[3]' does not match any association
+
+[test_duplicate_def_1]
+60_errors_and_warnings.c:128: error: redefinition of 'L'
+
+[test_duplicate_def_2]
+60_errors_and_warnings.c:131: error: redeclaration of 'L'