From e63a5fc02db3131f33e77efd95de0fad8c781c01 Mon Sep 17 00:00:00 2001 From: Christoph Mallon Date: Tue, 18 Nov 2008 19:26:58 +0000 Subject: [PATCH] =?utf8?q?Add=20semantic=20check:=20=C2=A76.8.5:2=20The=20?= =?utf8?q?controlling=20expression=20of=20an=20iteration=20statement=20sha?= =?utf8?q?ll=20have=20scalar=20type.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit [r23778] --- parser.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/parser.c b/parser.c index c26568a..a07ee45 100644 --- a/parser.c +++ b/parser.c @@ -9785,6 +9785,17 @@ static statement_t *parse_loop_body(statement_t *const loop) return body; } +static void check_conditon_type(expression_t const *const expr, + char const *const stmt_name) +{ + type_t *const type = skip_typeref(expr->base.type); + /* §6.8.5:2 */ + if (is_type_scalar(type) && is_type_valid(type)) { + errorf(&expr->base.source_position, + "condition of %s statement must have scalar type", stmt_name); + } +} + /** * Parse a while statement. */ @@ -9800,6 +9811,7 @@ static statement_t *parse_while(void) add_anchor_token(')'); expression_t *const cond = parse_expression(); statement->whiles.condition = cond; + check_conditon_type(cond, "while"); warn_reference_address_as_bool(cond); mark_vars_read(cond, NULL); rem_anchor_token(')'); @@ -9834,6 +9846,7 @@ static statement_t *parse_do(void) add_anchor_token(')'); expression_t *const cond = parse_expression(); statement->do_while.condition = cond; + check_conditon_type(cond, "do-while"); warn_reference_address_as_bool(cond); mark_vars_read(cond, NULL); rem_anchor_token(')'); @@ -9885,6 +9898,7 @@ static statement_t *parse_for(void) add_anchor_token(';'); expression_t *const cond = parse_expression(); statement->fors.condition = cond; + check_conditon_type(cond, "for"); warn_reference_address_as_bool(cond); mark_vars_read(cond, NULL); rem_anchor_token(';'); -- 2.20.1