Fixed handling of function definitions with an empty parameter list. According

to the standard, an empty parameter list in a function declarator that is not
a definition means that the function may have any number of parameters. In a
function definition, it means that there are no parameters (as if the function
were declared with a "void" parameter list).


git-svn-id: svn://svn.cc65.org/cc65/trunk@3865 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz 2008-08-03 15:30:03 +00:00
parent af9286852f
commit c76a8657b3

View file

@ -6,8 +6,8 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 2000-2004 Ullrich von Bassewitz */ /* (C) 2000-2008 Ullrich von Bassewitz */
/* Römerstrasse 52 */ /* Roemerstrasse 52 */
/* D-70794 Filderstadt */ /* D-70794 Filderstadt */
/* EMail: uz@cc65.org */ /* EMail: uz@cc65.org */
/* */ /* */
@ -250,12 +250,28 @@ static void Parse (void)
if (CurTok.Tok == TOK_SEMI) { if (CurTok.Tok == TOK_SEMI) {
/* Prototype only */ /* Prototype only */
NextToken (); NextToken ();
} else if (Entry) { } else {
/* Function body definition */
FuncDesc* D;
/* Function body. Check for duplicate function definitions */
if (SymIsDef (Entry)) { if (SymIsDef (Entry)) {
Error ("Body for function `%s' has already been defined", Error ("Body for function `%s' has already been defined",
Entry->Name); Entry->Name);
} }
/* An empty parameter list in a function definition means
* that the function doesn't take any parameters. The same
* in a declarator means that the function can take any
* number of parameters. This seems weird but is necessary
* to support old K&R style programs.
*/
D = Entry->V.F.Func;
if (D->Flags & FD_EMPTY) {
D->Flags = (D->Flags & ~(FD_EMPTY | FD_VARIADIC)) | FD_VOID_PARAM;
}
/* Parse the function body */
NewFunc (Entry); NewFunc (Entry);
} }
} }