Commit f35a963ac5

Vexu <git@vexu.eu>
2020-01-02 10:51:35
translate-c properly handle unused var-args
1 parent 576320e
Changed files (2)
src-self-hosted
test
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);
 
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 {}
     });
 }