Move adding/removing ';' as anchor from intern_parse_statement() to parse_compound_st...
[cparser] / parser.c
index ad746a0..18c59f6 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -3220,7 +3220,11 @@ static bool has_parameters(void)
                type_t const *const type = skip_typeref(entity->typedefe.type);
                if (!is_type_void(type))
                        return true;
-               if (type->base.qualifiers != TYPE_QUALIFIER_NONE) {
+               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");
                }
@@ -9997,7 +10001,6 @@ static statement_t *intern_parse_statement(void)
        statement_t *statement = NULL;
 
        /* declaration or statement */
-       add_anchor_token(';');
        switch (token.kind) {
        case T_IDENTIFIER: {
                token_kind_t la1_type = (token_kind_t)look_ahead(1)->kind;
@@ -10068,11 +10071,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);
@@ -10120,6 +10121,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);
@@ -10332,6 +10334,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('*');