From 770d7febc8c3875b5cff11020100f6d0f0f1a665 Mon Sep 17 00:00:00 2001 From: Michael Beck Date: Wed, 12 Dec 2007 17:23:00 +0000 Subject: [PATCH] - functions returning arrays are not allowed - enum types can be incomplete like coumpound types [r18718] --- parser.c | 4 ++++ parsetest/shouldfail/function_return.c | 2 ++ type.c | 9 ++++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/parser.c b/parser.c index 465f817..200c70f 100644 --- a/parser.c +++ b/parser.c @@ -2443,6 +2443,10 @@ static declaration_t *record_declaration(declaration_t *declaration) errorf(declaration->source_position, "'%Y' declared as function returning a function", declaration->symbol); declaration->type = type_error_type; + } else if (ret_type->kind == TYPE_ARRAY) { + errorf(declaration->source_position, "'%Y' declared as function returning an array", + declaration->symbol); + declaration->type = type_error_type; } } if (! is_valid_array_type(type)) { diff --git a/parsetest/shouldfail/function_return.c b/parsetest/shouldfail/function_return.c index adcde69..099bf4e 100644 --- a/parsetest/shouldfail/function_return.c +++ b/parsetest/shouldfail/function_return.c @@ -1,8 +1,10 @@ typedef int (function)(int); typedef void broken_array[8]; +typedef int int_array[8]; broken_array x; function test(void); broken_array test2(void); +int_array test3(void); diff --git a/type.c b/type.c index 9594ae8..fb835e7 100644 --- a/type.c +++ b/type.c @@ -539,6 +539,9 @@ bool is_type_scalar(const type_t *type) return is_type_arithmetic(type); } +/** + * Check if a given type is incomplete + */ bool is_type_incomplete(const type_t *type) { assert(!is_typeref(type)); @@ -550,6 +553,11 @@ bool is_type_incomplete(const type_t *type) declaration_t *declaration = compound_type->declaration; return !declaration->init.is_defined; } + case TYPE_ENUM: { + const enum_type_t *enum_type = &type->enumt; + declaration_t *declaration = enum_type->declaration; + return !declaration->init.is_defined; + } case TYPE_BITFIELD: case TYPE_FUNCTION: return true; @@ -561,7 +569,6 @@ bool is_type_incomplete(const type_t *type) return type->atomic.akind == ATOMIC_TYPE_VOID; case TYPE_POINTER: - case TYPE_ENUM: case TYPE_BUILTIN: return false; -- 2.20.1