From: Christoph Mallon Date: Fri, 12 Sep 2008 18:30:06 +0000 (+0000) Subject: Check whether the operand of ++/-- is an lvalue. X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=886ff023e631c68524b788a8888576cd21f4cb7a;p=cparser Check whether the operand of ++/-- is an lvalue. [r21904] --- diff --git a/parser.c b/parser.c index 5f4834d..c8049e1 100644 --- a/parser.c +++ b/parser.c @@ -7149,6 +7149,20 @@ static bool check_pointer_arithmetic(const source_position_t *source_position, return true; } +static bool is_lvalue(const expression_t *expression) +{ + switch (expression->kind) { + case EXPR_REFERENCE: + case EXPR_ARRAY_ACCESS: + case EXPR_SELECT: + case EXPR_UNARY_DEREFERENCE: + return true; + + default: + return false; + } +} + static void semantic_incdec(unary_expression_t *expression) { type_t *const orig_type = expression->value->base.type; @@ -7164,6 +7178,10 @@ static void semantic_incdec(unary_expression_t *expression) "operation needs an arithmetic or pointer type"); return; } + if (!is_lvalue(expression->value)) { + /* TODO: improve error message */ + errorf(&expression->base.source_position, "lvalue required as operand"); + } expression->base.type = orig_type; } @@ -7617,20 +7635,6 @@ static bool has_const_fields(const compound_type_t *type) return false; } -static bool is_lvalue(const expression_t *expression) -{ - switch (expression->kind) { - case EXPR_REFERENCE: - case EXPR_ARRAY_ACCESS: - case EXPR_SELECT: - case EXPR_UNARY_DEREFERENCE: - return true; - - default: - return false; - } -} - static bool is_valid_assignment_lhs(expression_t const* const left) { type_t *const orig_type_left = revert_automatic_type_conversion(left);