Skip to content

Variadic function-pointer types: c_import emits extern "C" fn(c_int, ...) -> c_int, which does not parse #1832

Closed

Description

@ehartford

c_import renders a C variadic function-pointer type with a trailing ..., but the type grammar (parse_fn_type_node) has no ...:

use c_import("typedef int (*vfn)(int, ...);\nstatic inline int call_it(vfn f) { return f(2, 30, 12); }")
fn main:
    print("x")
error: expected type
32 | type vfn = extern "C" fn(c_int, ...) -> c_int

(v0.15.2.1 and the D75 branch.) There is also no Sema type for it: TY_FN/TY_EXTERN_FN carry no variadic bit, so a call through such a pointer could not use the variadic convention.

D75 (§16.2b.5, #1678) consequence: a With function defined with ... has no function-pointer type, so the implementation refuses it as a value (is defined with ...: it is called directly (under unsafe), never used as a value); C reaches it only by its exported symbol (@[c_export]). Passing one as a callback (a logging hook typed int (*)(const char *, ...)) needs this type — spec text for it is owed (the spec states no variadic callable type).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions