In a case like typedef int T[1]; const T x; we must make a copy of the typedef type so that we can add the type qualifiers to it. The following code used to give error: incompatible types for redefinition of 'f' typedef int T[1]; void f(const int [1]); void f(const T);
Unified · Split
| @@ -3314,7 +3314,17 @@ static int parse_btype(CType *type, AttributeDef *ad) · 3313 unmodified lines | ||
| 3314 | 3314 | if (!s || !(s->type.t & VT_TYPEDEF)) |
| 3315 | 3315 | goto the_end; |
| 3316 | 3316 | t |= (s->type.t & ~VT_TYPEDEF); |
| 3317 | − type->ref = s->type.ref; | |
| 3317 | + if ((t & VT_ARRAY) && | |
| 3318 | + t & (VT_CONSTANT | VT_VOLATILE) & ~s->type.ref->type.t) { | |
| 3319 | + /* This is a case like "typedef int T[1]; const T x;" | |
| 3320 | + in which which we must make a copy of the typedef | |
| 3321 | + type so that we can add the type qualifiers to it. */ | |
| 3322 | + type->ref = sym_push(SYM_FIELD, &s->type.ref->type, | |
| 3323 | + 0, s->type.ref->c); | |
| 3324 | + type->ref->type.t |= t & (VT_CONSTANT | VT_VOLATILE); | |
| 3325 | + } | |
| 3326 | + else | |
| 3327 | + type->ref = s->type.ref; | |
| 3318 | 3328 | if (s->r) { |
| 3319 | 3329 | /* get attributes from typedef */ |
| 3320 | 3330 | if (0 == ad->a.aligned) |