| @@ -2927,13 +2927,10 @@ static void struct_decl(CType *type, AttributeDef *ad, int u) · 2926 unmodified lines |
| 2927 | 2927 | if (v < TOK_IDENT) |
| 2928 | 2928 | expect("struct/union/enum name"); |
| 2929 | 2929 | s = struct_find(v); |
| 2930 | | − if (s && s->type.t == a) { |
| 2931 | | − if (0 == local_scope) |
| 2932 | | − goto do_decl; /* compatibility with past behavior */ |
| 2933 | | − if (tok != '{' && tok != ';') |
| 2934 | | − goto do_decl; /* variable declaration: 'struct s x;' */ |
| 2935 | | − if (s->scope == local_scope && (s->c == -1 || tok != '{')) |
| 2936 | | − goto do_decl; /* at least one must be incomplete type */ |
| 2930 | + if (s && (s->scope == local_scope || (tok != '{' && tok != ';'))) { |
| 2931 | + if (s->type.t != a) |
| 2932 | + tcc_error("redefinition of '%s'", get_tok_str(v, NULL)); |
| 2933 | + goto do_decl; |
| 2937 | 2934 | } |
| 2938 | 2935 | } else { |
| 2939 | 2936 | v = anon_sym++; |
| @@ -3435,8 +3432,6 @@ static void post_type(CType *type, AttributeDef *ad) · 495 unmodified lines |
| 3435 | 3432 | plast = &first; |
| 3436 | 3433 | arg_size = 0; |
| 3437 | 3434 | if (tok != ')') { |
| 3438 | | − int ls = local_scope; |
| 3439 | | − local_scope = 1; /* for struct decl inside function params */ |
| 3440 | 3435 | for(;;) { |
| 3441 | 3436 | /* read param name and compute offset */ |
| 3442 | 3437 | if (l != FUNC_OLD) { |
| @@ -3476,7 +3471,6 @@ static void post_type(CType *type, AttributeDef *ad) · 33 unmodified lines |
| 3476 | 3471 | break; |
| 3477 | 3472 | } |
| 3478 | 3473 | } |
| 3479 | | − local_scope = ls; |
| 3480 | 3474 | } |
| 3481 | 3475 | /* if no parameters, then old type prototype */ |
| 3482 | 3476 | if (l == 0) |
| @@ -6434,7 +6428,16 @@ static int decl0(int l, int is_for_loop_init) · 2951 unmodified lines |
| 6434 | 6428 | if (btype.t & VT_TYPEDEF) { |
| 6435 | 6429 | /* save typedefed type */ |
| 6436 | 6430 | /* XXX: test storage specifiers ? */ |
| 6437 | | − sym = sym_push(v, &type, 0, 0); |
| 6431 | + sym = sym_find(v); |
| 6432 | + if (sym && sym->scope == local_scope) { |
| 6433 | + if (!is_compatible_types(&sym->type, &type) |
| 6434 | + || !(sym->type.t & VT_TYPEDEF)) |
| 6435 | + tcc_error("incompatible redefinition of '%s'", |
| 6436 | + get_tok_str(v, NULL)); |
| 6437 | + sym->type = type; |
| 6438 | + } else { |
| 6439 | + sym = sym_push(v, &type, 0, 0); |
| 6440 | + } |
| 6438 | 6441 | sym->a = ad.a; |
| 6439 | 6442 | sym->type.t |= VT_TYPEDEF; |
| 6440 | 6443 | } else { |