aboutsummaryrefslogtreecommitdiff
path: root/expr.c
diff options
context:
space:
mode:
Diffstat (limited to 'expr.c')
-rw-r--r--expr.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/expr.c b/expr.c
index 501e0e5..a09f2d6 100644
--- a/expr.c
+++ b/expr.c
@@ -847,13 +847,15 @@ condexpr(struct scope *s)
}
uint64_t
-intconstexpr(struct scope *s)
+intconstexpr(struct scope *s, bool allowneg)
{
struct expression *e;
e = eval(condexpr(s));
if (e->kind != EXPRCONST || !(typeprop(e->type) & PROPINT))
error(&tok.loc, "not an integer constant expression");
+ if (!allowneg && e->type->basic.issigned && e->constant.i > INT64_MAX)
+ error(&tok.loc, "integer constant expression cannot be negative");
return e->constant.i;
}