Skip to content

Bindgen gets confused by external inline function definition #2158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Tazdevil971 opened this issue Feb 10, 2022 · 1 comment · Fixed by #2340
Closed

Bindgen gets confused by external inline function definition #2158

Tazdevil971 opened this issue Feb 10, 2022 · 1 comment · Fixed by #2340

Comments

@Tazdevil971
Copy link

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.

@pvdrz
Copy link
Contributor

pvdrz commented Oct 7, 2022

Hmmm I have noticed some finicky details about how inline is handled and I remember seeing a different instance of this using C and not C++.

Not directly related but some of the machinery that will be introduced to fix #1090 might be able to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants