Skip to content

Commit

Permalink
Parser: fix parenthesized names not being allowed on func definitions
Browse files Browse the repository at this point in the history
Closes #538
  • Loading branch information
Vexu committed Nov 7, 2023
1 parent 75d5b44 commit 1cdf4d5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1680,7 +1680,9 @@ fn initDeclarator(p: *Parser, decl_spec: *DeclSpec, attr_buf_top: usize) Error!?
}

if (p.eatToken(.equal)) |eq| init: {
if (decl_spec.storage_class == .typedef or init_d.d.func_declarator != null) {
if (decl_spec.storage_class == .typedef or
(init_d.d.func_declarator != null and init_d.d.ty.isFunc()))
{
try p.errTok(.illegal_initializer, eq);
} else if (init_d.d.ty.is(.variable_len_array)) {
try p.errTok(.vla_init, eq);
Expand Down Expand Up @@ -2792,6 +2794,7 @@ fn declarator(
try res.ty.combine(outer);
try res.ty.validateCombinedType(p, suffix_start);
res.old_style_func = d.old_style_func;
res.func_declarator = d.func_declarator;
return res;
}

Expand Down
3 changes: 3 additions & 0 deletions test/cases/functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ void static_array_parameter(x)
int x[static 5];
{}

int(wrapped)(void) {
return 0;
}

#define EXPECTED_ERRORS "functions.c:10:12: error: parameter named 'quux' is missing" \
"functions.c:20:14: error: illegal initializer (only variables can be initialized)" \
Expand Down

0 comments on commit 1cdf4d5

Please sign in to comment.