previously, tcc would accept a prototype of a function returning an array, but not giving those functions bodies nor calling them. it seems that gcc has never supported them, so we should probably just error out... but it's possible that someone already using tcc includes some header that contains an unused prototype for one, so let's continue to support that.
Unified · Split
| @@ -3108,19 +3108,22 @@ static void post_type(CType *type, AttributeDef *ad) · 3107 unmodified lines | ||
| 3108 | 3108 | if (l == 0) |
| 3109 | 3109 | l = FUNC_OLD; |
| 3110 | 3110 | skip(')'); |
| 3111 | − t1 = type->t & VT_STORAGE; | |
| 3112 | 3111 | /* NOTE: const is ignored in returned type as it has a special |
| 3113 | 3112 | meaning in gcc / C++ */ |
| 3114 | − type->t &= ~(VT_STORAGE | VT_CONSTANT); | |
| 3113 | + type->t &= ~VT_CONSTANT; | |
| 3115 | 3114 | /* some ancient pre-K&R C allows a function to return an array |
| 3116 | 3115 | and the array brackets to be put after the arguments, such |
| 3117 | − that "int c()[]" means the same as "int[] c()" */ | |
| 3118 | − post_type(type, ad); | |
| 3116 | + that "int c()[]" means something like "int[] c()" */ | |
| 3117 | + if (tok == '[') { | |
| 3118 | + next(); | |
| 3119 | + skip(']'); /* only handle simple "[]" */ | |
| 3120 | + type->t |= VT_PTR; | |
| 3121 | + } | |
| 3119 | 3122 | /* we push a anonymous symbol which will contain the function prototype */ |
| 3120 | 3123 | ad->func_args = arg_size; |
| 3121 | 3124 | s = sym_push(SYM_FIELD, type, INT_ATTR(ad), l); |
| 3122 | 3125 | s->next = first; |
| 3123 | − type->t = t1 | VT_FUNC; | |
| 3126 | + type->t |= VT_FUNC; | |
| 3124 | 3127 | type->ref = s; |
| 3125 | 3128 | } else if (tok == '[') { |
| 3126 | 3129 | /* array definition */ |