Accept `void` as a parameter list

`foo(void)` indicate that function foo does not take a parameter.
This commit is contained in:
Rui Ueyama 2019-08-20 08:30:43 +09:00
parent 1e7c50c454
commit 7938157072
2 changed files with 7 additions and 2 deletions

View File

@ -540,6 +540,11 @@ VarList *read_func_params() {
if (consume(")"))
return NULL;
Token *tok = token;
if (consume("void") && consume(")"))
return NULL;
token = tok;
VarList *head = read_func_param();
VarList *cur = head;
@ -553,7 +558,7 @@ VarList *read_func_params() {
}
// function = type-specifier declarator "(" params? ")" ("{" stmt* "}" | ";")
// params = param ("," param)*
// params = param ("," param)* | "void"
// param = type-specifier declarator type-suffix
Function *function() {
locals = NULL;

2
tests
View File

@ -94,7 +94,7 @@ int count() {
int param_decay(int x[]) { return x[0]; }
void voidfn() {}
void voidfn(void) {}
int main() {
assert(8, ({ int a=3; int z=5; a+z; }), "int a=3; int z=5; a+z;");