Skip to content

Bindgen gets confused by external inline function definition #2158

Closed
@Tazdevil971

Description

@Tazdevil971

Input C/C++ Header

class Foo {
public:
    void bar();
};

inline void Foo::bar() {
    // Oh-no
}

Bindgen Invocation

Generated by bindgen input.hpp, no flags

/* automatically generated by rust-bindgen 0.59.2 */

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Foo {
    pub _address: u8,
}
#[test]
fn bindgen_test_layout_Foo() {
    assert_eq!(
        ::std::mem::size_of::<Foo>(),
        1usize,
        concat!("Size of: ", stringify!(Foo))
    );
    assert_eq!(
        ::std::mem::align_of::<Foo>(),
        1usize,
        concat!("Alignment of ", stringify!(Foo))
    );
}
extern "C" {
    #[link_name = "\u{1}_ZN3Foo3barEv"]
    pub fn Foo_bar(this: *mut Foo);
}
impl Foo {
    #[inline]
    pub unsafe fn bar(&mut self) {
        Foo_bar(self)
    }
}

Expected Results

Bindgen shouldn't be generating bindings for bar(). It probably gets confused by the fact that Foo's declaration doesn't specifically say that bar() is inline, but instead it should look forward for a possible inline definition.

Marking the bar() declaration with inline does fix the issue, even if we don't provide an actual body.

The specific header I'm working with is this one, and it makes heavy usage of this to define std dependent helpers.

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