Unified · Split
| @@ -3166,13 +3166,13 @@ static void post_type(CType *type, AttributeDef *ad) · 3165 unmodified lines | |||
| 3166 | n = -1; | 3166 | n = -1; |
| 3167 | t1 = 0; | 3167 | t1 = 0; |
| 3168 | if (tok != ']') { | 3168 | if (tok != ']') { |
| 3169 | gexpr(); | 3169 | if (!local_stack || nocode_wanted) |
| 3170 | vpushi(expr_const()); | ||
| 3171 | else gexpr(); | ||
| 3170 | if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) { | 3172 | if ((vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST) { |
| 3171 | n = vtop->c.i; | 3173 | n = vtop->c.i; |
| 3172 | if (n < 0) | 3174 | if (n < 0) |
| 3173 | error("invalid array size"); | 3175 | error("invalid array size"); |
| 3174 | } else if (!local_stack) { | ||
| 3175 | error("expected constant expression (variably modified array at file scope)"); | ||
| 3176 | } else { | 3176 | } else { |
| 3177 | if (!is_integer_btype(vtop->type.t & VT_BTYPE)) | 3177 | if (!is_integer_btype(vtop->type.t & VT_BTYPE)) |
| 3178 | error("size of variable length array should be an integer"); | 3178 | error("size of variable length array should be an integer"); |
| @@ -2083,6 +2083,8 @@ void *bounds_checking_is_enabled() · 2082 unmodified lines | |||
| 2083 | return (ca != cp + 1) ? cp : NULL; | 2083 | return (ca != cp + 1) ? cp : NULL; |
| 2084 | } | 2084 | } |
| 2085 | 2085 | ||
| 2086 | typedef int constant_negative_array_size_as_compile_time_assertion_idiom[(1 ? 2 : 0) - 1]; | ||
| 2087 | |||
| 2086 | void c99_vla_test(int size1, int size2) | 2088 | void c99_vla_test(int size1, int size2) |
| 2087 | { | 2089 | { |
| 2088 | #if defined __i386__ || defined __x86_64__ | 2090 | #if defined __i386__ || defined __x86_64__ |