translate-c properly handle unused var-args

master
Vexu 2020-01-02 11:51:35 +02:00 committed by Andrew Kelley
parent 576320e6d5
commit f35a963ac5
2 changed files with 10 additions and 2 deletions

View File

@ -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);

View File

@ -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 {}
});
}