rust-bindgen icon indicating copy to clipboard operation
rust-bindgen copied to clipboard

Disallow passing `_Complex` by value

Open SabrinaJewson opened this issue 4 months ago • 0 comments

As seen in https://github.com/rust-lang/rfcs/issues/793 and https://github.com/rust-lang/libc/issues/355, C’s _Complex has a different ABI (but not layout) to what Bindgen currently generates, which is:

#[derive(PartialEq, Copy, Clone, Hash, Debug, Default)]
#[repr(C)]
pub struct __BindgenComplex<T> {
    pub re: T,
    pub im: T,
}

As a soundness fix, I suggest erroring when the user attempts to use _Complex by value. Maybe this could be done with a flag to disable it if the user really wants the potentially-unsound behaviour?

SabrinaJewson avatar Jul 24 '25 21:07 SabrinaJewson