From f35a963ac5a2ea053801c37be1271153f35b7df1 Mon Sep 17 00:00:00 2001 From: Vexu Date: Thu, 2 Jan 2020 11:51:35 +0200 Subject: [PATCH] translate-c properly handle unused var-args --- src-self-hosted/translate_c.zig | 10 ++++++++-- test/translate_c.zig | 2 ++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src-self-hosted/translate_c.zig b/src-self-hosted/translate_c.zig index d0cb778bf..f336d355d 100644 --- a/src-self-hosted/translate_c.zig +++ b/src-self-hosted/translate_c.zig @@ -477,8 +477,14 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void { var it = proto_node.params.iterator(0); while (it.next()) |p| { const param = @fieldParentPtr(ast.Node.ParamDecl, "base", p.*); - const param_name = tokenSlice(c, param.name_token orelse - return failDecl(c, fn_decl_loc, fn_name, "function {} parameter has no name", .{fn_name})); + const param_name = if (param.name_token) |name_tok| + tokenSlice(c, name_tok) + else if (param.var_args_token != null) { + assert(it.next() == null); + _ = proto_node.params.pop(); + break; + } else + return failDecl(c, fn_decl_loc, fn_name, "function {} parameter has no name", .{fn_name}); const mangled_param_name = try block_scope.makeMangledName(c, param_name); diff --git a/test/translate_c.zig b/test/translate_c.zig index 5de9abcbe..40a5e4a34 100644 --- a/test/translate_c.zig +++ b/test/translate_c.zig @@ -2307,9 +2307,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\inline void a(void) {} \\static void b(void) {} \\void c(void) {} + \\static void foo() {} , &[_][]const u8{ \\pub fn a() void {} \\pub fn b() void {} \\pub export fn c() void {} + \\pub fn foo() void {} }); }