Skip to content

PhantomData is not foreign-function safe #442

Closed
@rillian

Description

@rillian

On my system (Fedora Linux 25) bindgen generates a PhantomData-based union representation for fpos_t from stdio. Rustc (1.14 or 1.15) complains about this:

warning: found non-foreign-function-safe member in struct marked #[repr(C)]: found struct without foreign-function-safe representation annotation in foreign module, consider adding a #[repr(C)] attribute to the type, #[warn(improper_ctypes)] on by default
14 |     pub fn fgetpos(__stream: *mut FILE, __pos: *mut fpos_t)
   |                                                ^^^^^^^^^^^

Here's a reduced example:

#[repr(C)]
pub struct FILE;

#[repr(C)]
#[allow(non_camel_case_types)]
pub struct fpos_t {
    pub __value: ::std::marker::PhantomData<::std::os::raw::c_uint>,
}

extern "C" {
    pub fn fgetpos(__stream: *mut FILE, __pos: *mut fpos_t)
     -> ::std::os::raw::c_int;
}

It would be good if the generated code compiled without warnings.

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