X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;ds=sidebyside;f=parser.c;h=f1bbaa64ada5d7b52d457a9479e3e6d53b4bf214;hb=3ebfcac30456a053d3eba3fb1a2df7b1e73668b8;hp=c5c354592031f42d82e970ae945d12c632621a4a;hpb=e1432a496fed91dd4fee062dcdc9007718c77758;p=cparser diff --git a/parser.c b/parser.c index c5c3545..f1bbaa6 100644 --- a/parser.c +++ b/parser.c @@ -3208,6 +3208,8 @@ static void semantic_parameter_incomplete(const entity_t *entity) static bool has_parameters(void) { /* func(void) is not a parameter */ + if (look_ahead(1)->kind != ')') + return true; if (token.kind == T_IDENTIFIER) { entity_t const *const entity = get_entity(token.identifier.symbol, NAMESPACE_NORMAL); @@ -3215,13 +3217,20 @@ static bool has_parameters(void) return true; if (entity->kind != ENTITY_TYPEDEF) return true; - if (skip_typeref(entity->typedefe.type) != type_void) + type_t const *const type = skip_typeref(entity->typedefe.type); + if (!is_type_void(type)) return true; + if (c_mode & _CXX) { + /* ISO/IEC 14882:1998(E) §8.3.5:2 It must be literally (void). A typedef + * is not allowed. */ + errorf(HERE, "empty parameter list defined with a typedef of 'void' not allowed in C++"); + } else if (type->base.qualifiers != TYPE_QUALIFIER_NONE) { + /* §6.7.5.3:10 Qualification is not allowed here. */ + errorf(HERE, "'void' as parameter must not have type qualifiers"); + } } else if (token.kind != T_void) { return true; } - if (look_ahead(1)->kind != ')') - return true; next_token(); return false; } @@ -6273,7 +6282,7 @@ static bool semantic_cast(expression_t *cast) source_position_t const *pos = &cast->base.source_position; /* §6.5.4 A (void) cast is explicitly permitted, more for documentation than for utility. */ - if (dst_type == type_void) + if (is_type_void(dst_type)) return true; /* only integer and pointer can be casted to pointer */ @@ -9989,10 +9998,8 @@ end_error: */ static statement_t *intern_parse_statement(void) { - statement_t *statement = NULL; - /* declaration or statement */ - add_anchor_token(';'); + statement_t *statement; switch (token.kind) { case T_IDENTIFIER: { token_kind_t la1_type = (token_kind_t)look_ahead(1)->kind; @@ -10063,14 +10070,9 @@ static statement_t *intern_parse_statement(void) default: errorf(HERE, "unexpected token %K while parsing statement", &token); statement = create_error_statement(); - if (!at_anchor()) - next_token(); + eat_until_anchor(); break; } - rem_anchor_token(';'); - - assert(statement != NULL - && statement->base.source_position.input_name != NULL); return statement; } @@ -10115,6 +10117,7 @@ static statement_t *parse_compound_statement(bool inside_expression_statement) add_anchor_token('*'); add_anchor_token('+'); add_anchor_token('-'); + add_anchor_token(';'); add_anchor_token('{'); add_anchor_token('~'); add_anchor_token(T_CHARACTER_CONSTANT); @@ -10327,6 +10330,7 @@ end_error: rem_anchor_token(T_CHARACTER_CONSTANT); rem_anchor_token('~'); rem_anchor_token('{'); + rem_anchor_token(';'); rem_anchor_token('-'); rem_anchor_token('+'); rem_anchor_token('*');