Skip to content

Failed layout test, when template is referencing opaque template #1018

@usamec

Description

@usamec

Input C/C++ Header

template<class T>
class B {
  T* x;
};

template<class T>
class A {
 public:
  void a();
  B<T> x;
};

template class A<double>;

Bindgen Invocation

$bindgen test_bind2.hpp -o src/bindings.rs --opaque-type "B" -- -x c++

Actual Results

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct B {
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct A {
    pub x: u8,
}
#[test]
fn __bindgen_test_layout_A_open0_double_close0_instantiation() {
    assert_eq!(::std::mem::size_of::<A>() , 8usize , concat ! (
               "Size of template specialization: " , stringify ! ( A ) ));
    assert_eq!(::std::mem::align_of::<A>() , 8usize , concat ! (
               "Alignment of template specialization: " , stringify ! ( A )
               ));
}

Expected Results

When running test we get

failures:

---- __bindgen_test_layout_A_open0_double_close0_instantiation stdout ----
        thread '__bindgen_test_layout_A_open0_double_close0_instantiation' panicked at 'assertion failed: `(left == right)`
  left: `1`,
 right: `8`: Size of template specialization: A', src/bindings.rs:14:4
note: Run with `RUST_BACKTRACE=1` for a backtrace.

Apparently x: u8 is wrong.

When invoked without opaque inner type it works:

bindgen test_bind2.hpp -o src/bindings.rs -- -x c++

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions