Skip to content

Emit wrong layout with inheriting from zero-sized type parameters #586

@fitzgen

Description

@fitzgen

Input C/C++ Header

namespace JS {
namespace detail {
class a {};
template <class b> class CallArgsBase : b {
  int *c;
  unsigned d;
};
}
}
class B : JS::detail::CallArgsBase<JS::detail::a> {};

Bindgen Invokation

$ bindgen input.hpp --enable-cxx-namespaces -- -std=c++14

Actual Results

Compiles into this:

/* automatically generated by rust-bindgen */

#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)]
pub mod root {
    #[allow(unused_imports)]
    use self::super::root;
    pub mod JS {
        #[allow(unused_imports)]
        use self::super::super::root;
        pub mod detail {
            #[allow(unused_imports)]
            use self::super::super::super::root;
            #[repr(C)]
            #[derive(Debug, Copy)]
            pub struct a {
                pub _address: u8,
            }
            #[test]
            fn bindgen_test_layout_a() {
                assert_eq!(::std::mem::size_of::<a>() , 1usize , concat ! (
                           "Size of: " , stringify ! ( a ) ));
                assert_eq! (::std::mem::align_of::<a>() , 1usize , concat ! (
                            "Alignment of " , stringify ! ( a ) ));
            }
            impl Clone for a {
                fn clone(&self) -> Self { *self }
            }
            #[repr(C)]
            #[derive(Debug, Copy, Clone)]
            pub struct CallArgsBase<b> {
                pub _base: b,
                pub c: *mut ::std::os::raw::c_int,
                pub d: ::std::os::raw::c_uint,
            }
        }
    }
    #[test]
    fn __bindgen_test_layout_CallArgsBase_instantiation_16() {
        assert_eq!(::std::mem::size_of::<root::JS::detail::CallArgsBase<root::JS::detail::a>>()
                   , 16usize , concat ! (
                   "Size of template specialization: " , stringify ! (
                   root::JS::detail::CallArgsBase<root::JS::detail::a> ) ));
        assert_eq!(::std::mem::align_of::<root::JS::detail::CallArgsBase<root::JS::detail::a>>()
                   , 8usize , concat ! (
                   "Alignment of template specialization: " , stringify ! (
                   root::JS::detail::CallArgsBase<root::JS::detail::a> ) ));
    }
}

And results in this layout test failure:

running 2 tests
test root::JS::detail::bindgen_test_layout_a ... ok
test root::__bindgen_test_layout_CallArgsBase_instantiation_16 ... FAILED

failures:

---- root::__bindgen_test_layout_CallArgsBase_instantiation_16 stdout ----
	thread 'root::__bindgen_test_layout_CallArgsBase_instantiation_16' panicked at 'assertion failed: `(left == right)` (left: `24`, right: `16`): Size of template specialization: root :: JS :: detail :: CallArgsBase < root :: JS :: detail :: a >', ./js.rs:41
note: Run with `RUST_BACKTRACE=1` for a backtrace.


failures:
    root::__bindgen_test_layout_CallArgsBase_instantiation_16

test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured

Expected Results

Maybe opaque blobs, but never any layout test failures.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions