Check whether the operand of ++/-- is an lvalue.
authorChristoph Mallon <christoph.mallon@gmx.de>
Fri, 12 Sep 2008 18:30:06 +0000 (18:30 +0000)
committerChristoph Mallon <christoph.mallon@gmx.de>
Fri, 12 Sep 2008 18:30:06 +0000 (18:30 +0000)
[r21904]

parser.c

index 5f4834d..c8049e1 100644 (file)
--- 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);