More accurate diagnostic messages on empty declarations without any type specifiers.

This commit is contained in:
acqn 2023-12-10 20:21:50 +08:00
parent b1c1502494
commit befc9533c6
3 changed files with 8 additions and 5 deletions

View File

@ -2087,10 +2087,13 @@ static void DirectDecl (DeclSpec* Spec, Declarator* D, declmode_t Mode)
NextToken ();
} else {
D->Ident[0] = '\0';
if ((Spec->Flags & DS_NO_EMPTY_DECL) != 0 &&
CurTok.Tok != TOK_LBRACK &&
if (CurTok.Tok != TOK_LBRACK &&
((Spec->Flags & DS_ALLOW_BITFIELD) == 0 || CurTok.Tok != TOK_COLON)) {
Error ("Identifier expected");
if ((Spec->Flags & DS_TYPE_MASK) == DS_DEF_TYPE) {
Error ("Declaration specifier or identifier expected");
} else if ((Spec->Flags & DS_NO_EMPTY_DECL) != 0) {
Error ("Identifier expected");
}
}
}

View File

@ -1412,7 +1412,7 @@ static void Primary (ExprDesc* E)
} else {
/* Let's see if this is a C99-style declaration */
DeclSpec Spec;
ParseDeclSpec (&Spec, TS_DEFAULT_TYPE_NONE, SC_AUTO);
ParseDeclSpec (&Spec, TS_DEFAULT_TYPE_INT, SC_AUTO);
if ((Spec.Flags & DS_TYPE_MASK) != DS_NONE) {
Error ("Mixed declarations and code are not supported in cc65");

View File

@ -1,3 +1,3 @@
bug1889-missing-identifier.c:3: Error: Identifier or ';' expected after declaration specifiers
bug1889-missing-identifier.c:3: Warning: Implicit 'int' is an obsolete feature
bug1889-missing-identifier.c:4: Error: Identifier expected
bug1889-missing-identifier.c:4: Error: Declaration specifier or identifier expected