From e83671e00f99d68d947ad7ccb35f1355f3f5aa97 Mon Sep 17 00:00:00 2001 From: Christoph Mallon Date: Wed, 27 Aug 2008 14:15:15 +0000 Subject: [PATCH] Set the error type as result type, if semantic check of ++/-- fails. [r21513] --- parser.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/parser.c b/parser.c index 0b2c587..ec5ca96 100644 --- a/parser.c +++ b/parser.c @@ -6946,7 +6946,7 @@ end_error: return create_invalid_expression(); } -static void check_pointer_arithmetic(const source_position_t *source_position, +static bool check_pointer_arithmetic(const source_position_t *source_position, type_t *pointer_type, type_t *orig_pointer_type) { @@ -6959,26 +6959,33 @@ static void check_pointer_arithmetic(const source_position_t *source_position, errorf(source_position, "arithmetic with pointer to incomplete type '%T' not allowed", orig_pointer_type); + return false; } else if (is_type_function(points_to)) { errorf(source_position, "arithmetic with pointer to function type '%T' not allowed", orig_pointer_type); + return false; } + return true; } static void semantic_incdec(unary_expression_t *expression) { type_t *const orig_type = expression->value->base.type; type_t *const type = skip_typeref(orig_type); + type_t * res_type = type; if (is_type_pointer(type)) { - check_pointer_arithmetic(&expression->base.source_position, - type, orig_type); + if (!check_pointer_arithmetic(&expression->base.source_position, + type, orig_type)) { + res_type = type_error_type; + } } else if (!is_type_real(type) && is_type_valid(type)) { /* TODO: improve error message */ errorf(&expression->base.source_position, "operation needs an arithmetic or pointer type"); + res_type = type_error_type; } - expression->base.type = orig_type; + expression->base.type = res_type; } static void semantic_unexpr_arithmetic(unary_expression_t *expression) -- 2.20.1