From e48346a9ee6debb722568b8356412559f34c9b60 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Wed, 15 Nov 2017 21:25:16 +0000 Subject: Disable negation of unsigned constants (Issue: #145) --- src/check_expr.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/check_expr.cpp') diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 1ed657ec8..707baaaf7 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -1494,6 +1494,13 @@ void check_unary_expr(Checker *c, Operand *o, Token op, AstNode *node) { o->mode = Addressing_Invalid; return; } + if (op.kind == Token_Sub && is_type_unsigned(type)) { + gbString err_str = expr_to_string(node); + error(op, "A unsigned constant cannot be negated '%s'", err_str); + gb_string_free(err_str); + o->mode = Addressing_Invalid; + return; + } o->value = exact_unary_operator_value(op.kind, o->value, precision); -- cgit v1.2.3