authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-01-02 11:51:35+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-01-02 10:39:52-05:00
logf35a963ac5a2ea053801c37be1271153f35b7df1
treef67d0656ab79be74b50bc1d66850b39240bcac0d
parent576320e6d5bf706a0ee03a3e9318c8ef2fd6e76f

translate-c properly handle unused var-args


2 files changed, 10 insertions(+), 2 deletions(-)

src-self-hosted/translate_c.zig+8-2
......@@ -477,8 +477,14 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void {
477477 var it = proto_node.params.iterator(0);
478478 while (it.next()) |p| {
479479 const param = @fieldParentPtr(ast.Node.ParamDecl, "base", p.*);
480 const param_name = tokenSlice(c, param.name_token orelse
481 return failDecl(c, fn_decl_loc, fn_name, "function {} parameter has no name", .{fn_name}));
480 const param_name = if (param.name_token) |name_tok|
481 tokenSlice(c, name_tok)
482 else if (param.var_args_token != null) {
483 assert(it.next() == null);
484 _ = proto_node.params.pop();
485 break;
486 } else
487 return failDecl(c, fn_decl_loc, fn_name, "function {} parameter has no name", .{fn_name});
482488
483489 const mangled_param_name = try block_scope.makeMangledName(c, param_name);
484490
test/translate_c.zig+2
......@@ -2307,9 +2307,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
23072307 \\inline void a(void) {}
23082308 \\static void b(void) {}
23092309 \\void c(void) {}
2310 \\static void foo() {}
23102311 , &[_][]const u8{
23112312 \\pub fn a() void {}
23122313 \\pub fn b() void {}
23132314 \\pub export fn c() void {}
2315 \\pub fn foo() void {}
23142316 });
23152317}