Skip to content
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

Error when including pure virtual subclass #1326

Open
d2weber opened this issue Aug 30, 2023 · 2 comments
Open

Error when including pure virtual subclass #1326

d2weber opened this issue Aug 30, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@d2weber
Copy link

d2weber commented Aug 30, 2023

Describe the bug
I get a build error in the autocxxgen_ffi.h code when including an abstract subclass.

To Reproduce
See #1325

Expected behavior
The build should succeed (the generated code should not try to act as if the type could be instantiated)

Additional context
Autocxx generates cxx glue code that causes errors like: invalid new-expression of abstract class type ‘B’.
I'm experiencing this Issue, because I would like to access a static method inside the abstract class like so:

struct A
{
    virtual int f() = 0;
};

struct B : virtual public A {
    static void i_want_this_function();
};
@adetaylor
Copy link
Collaborator

Thanks for the test case!

bindgen is giving us:

   
    #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)]
    pub mod root {
        #[allow(unused_imports)]
        use self::super::root;
        #[repr(C)]
        pub struct A__bindgen_vtable(::std::os::raw::c_void);
        #[repr(C)]
        #[cpp_semantics(layout(8, 8, false))]
        pub struct A {
            pub vtable_: *const A__bindgen_vtable,
        }
        extern "C" {
            #[cpp_semantics(pure_virtual)]
            #[cpp_semantics(bindgen_virtual)]
            #[cpp_semantics(original_name("f"))]
            #[link_name = "\u{1}__ZN1A1fEv"]
            pub fn A_f(this: *mut root::A) -> ::std::os::raw::c_int;
        }
        #[repr(C)]
        #[cpp_semantics(layout(8, 8, false))]
        pub struct B {
            pub __bindgen_padding_0: u64,
        }
    }
     }

i.e. bindgen is not telling us that B inherits from A, so therefore we make poor life choices around what to do with B.

It may be that this was because we make an invalid assumption about what output to expect from bindgen, I'll look into it in due course. Thanks again for the test case.

@adetaylor adetaylor added the bug Something isn't working label Sep 1, 2023
@adetaylor
Copy link
Collaborator

May be the same as #832

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants