diff options
author | Michael Forney <mforney@mforney.org> | 2019-05-18 17:10:50 -0700 |
---|---|---|
committer | Michael Forney <mforney@mforney.org> | 2019-05-18 17:10:50 -0700 |
commit | f41c37d7be16f7845795bae95e1356ca1f7a2fd6 (patch) | |
tree | 19a6681d83b609d83ccb155f2997d4a95eb7ab5e /decl.c | |
parent | f85d145c403fb267884f7fd4f762598bd30cc1b4 (diff) |
decl: Give a better error message when a VLA is used
Diffstat (limited to 'decl.c')
-rw-r--r-- | decl.c | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -450,6 +450,7 @@ declaratortypes(struct scope *s, struct list *result, char **name, bool allowabs struct list *ptr; struct type *t; struct param **p; + struct expr *e; uint64_t i; enum typequal tq; @@ -547,7 +548,13 @@ declaratortypes(struct scope *s, struct list *result, char **name, bool allowabs i = 0; next(); } else { - i = intconstexpr(s, false); + e = constexpr(s); + if (e->kind != EXPRCONST || !(e->type->prop & PROPINT)) + error(&tok.loc, "VLAs are not yet supported"); + i = e->constant.i; + if (i == 0 || e->type->basic.issigned && i > INT64_MAX) + error(&tok.loc, "array length must be positive"); + delexpr(e); expect(TRBRACK, "after array length"); } t = mkarraytype(NULL, tq, i); |