From 1cdf4d5380d72cd71d2a4c8dd552cd7eae4018c3 Mon Sep 17 00:00:00 2001 From: Veikka Tuominen Date: Tue, 7 Nov 2023 21:21:55 +0200 Subject: [PATCH] Parser: fix parenthesized names not being allowed on func definitions Closes #538 --- src/Parser.zig | 5 ++++- test/cases/functions.c | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Parser.zig b/src/Parser.zig index cc8ca820..1c82a25a 100644 --- a/src/Parser.zig +++ b/src/Parser.zig @@ -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); @@ -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; } diff --git a/test/cases/functions.c b/test/cases/functions.c index fd979612..6b7e5f26 100644 --- a/test/cases/functions.c +++ b/test/cases/functions.c @@ -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)" \