autocxx icon indicating copy to clipboard operation
autocxx copied to clipboard

Error when including pure virtual subclass

Open d2weber opened this issue 2 years ago • 3 comments

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();
};

d2weber avatar Aug 30 '23 17:08 d2weber

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 avatar Aug 30 '23 17:08 adetaylor

May be the same as #832

adetaylor avatar Sep 11 '23 11:09 adetaylor