From ab9abdc9b3e520d4e94b10de3fa2380c7a5a15f3 Mon Sep 17 00:00:00 2001 From: Christoph Mallon Date: Sat, 13 Sep 2008 10:20:44 +0000 Subject: [PATCH] Prevent warning about incompatible types when initializing a function like a variable. Only show the error message (which is also slightly improved). [r21923] --- parser.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/parser.c b/parser.c index df3ddd9..e9dd619 100644 --- a/parser.c +++ b/parser.c @@ -4424,6 +4424,13 @@ static void parse_init_declarator_rest(declaration_t *declaration) must_be_constant = true; } + if (is_type_function(type)) { + errorf(&declaration->source_position, + "function %#T is initialized like a variable", + orig_type, declaration->symbol); + orig_type = type_error_type; + } + parse_initializer_env_t env; env.type = orig_type; env.must_be_constant = must_be_constant; @@ -4432,17 +4439,10 @@ static void parse_init_declarator_rest(declaration_t *declaration) initializer_t *initializer = parse_initializer(&env); current_init_decl = NULL; - if (env.type != orig_type) { - orig_type = env.type; - type = skip_typeref(orig_type); - declaration->type = env.type; - } - - if (is_type_function(type)) { - errorf(&declaration->source_position, - "initializers not allowed for function types at declarator '%Y' (type '%T')", - declaration->symbol, orig_type); - } else { + if (!is_type_function(type)) { + /* § 6.7.5 (22) array initializers for arrays with unknown size determine + * the array type size */ + declaration->type = env.type; declaration->init.initializer = initializer; } } -- 2.20.1