Skip to content

Destructor missing for templated class (like smart pointer) #1017

@usamec

Description

@usamec

Input C/C++ Header

template<class T>
class Pointer {
 private:
  T* data;
  char xx;
  char yy;
 public:
  Pointer(T* data);
  ~Pointer();

  int method();

  T& operator*();
  T* operator->();
};


class A {
 public:
  int b, c, d;
  Pointer<A> x;
};

Pointer<A> MakeA();

Bindgen Invocation

$ bindgen test_bind.hpp -o src/bindings.rs -- -x c++ -std=c++11

Actual Results

#[repr(C)]
#[derive(Debug)]
pub struct Pointer<T> {
    pub data: *mut T,
    pub xx: ::std::os::raw::c_char,
    pub yy: ::std::os::raw::c_char,
    pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
}
#[repr(C)]
#[derive(Debug)]
pub struct A {
    pub b: ::std::os::raw::c_int,
    pub c: ::std::os::raw::c_int,
    pub d: ::std::os::raw::c_int,
    pub x: Pointer<A>,
}
#[test]
fn bindgen_test_layout_A() {
    assert_eq!(::std::mem::size_of::<A>() , 32usize , concat ! (
               "Size of: " , stringify ! ( A ) ));
    assert_eq! (::std::mem::align_of::<A>() , 8usize , concat ! (
                "Alignment of " , stringify ! ( A ) ));
    assert_eq! (unsafe { & ( * ( 0 as * const A ) ) . b as * const _ as usize
                } , 0usize , concat ! (
                "Alignment of field: " , stringify ! ( A ) , "::" , stringify
                ! ( b ) ));
    assert_eq! (unsafe { & ( * ( 0 as * const A ) ) . c as * const _ as usize
                } , 4usize , concat ! (
                "Alignment of field: " , stringify ! ( A ) , "::" , stringify
                ! ( c ) ));
    assert_eq! (unsafe { & ( * ( 0 as * const A ) ) . d as * const _ as usize
                } , 8usize , concat ! (
                "Alignment of field: " , stringify ! ( A ) , "::" , stringify
                ! ( d ) ));
    assert_eq! (unsafe { & ( * ( 0 as * const A ) ) . x as * const _ as usize
                } , 16usize , concat ! (
                "Alignment of field: " , stringify ! ( A ) , "::" , stringify
                ! ( x ) ));
}
extern "C" {
    #[link_name = "_Z5MakeAv"]
    pub fn MakeA() -> Pointer<A>;
}
#[test]
fn __bindgen_test_layout_Pointer_open0_A_close0_instantiation() {
    assert_eq!(::std::mem::size_of::<Pointer<A>>() , 16usize , concat ! (
               "Size of template specialization: " , stringify ! ( Pointer<A>
               ) ));
    assert_eq!(::std::mem::align_of::<Pointer<A>>() , 8usize , concat ! (
               "Alignment of template specialization: " , stringify ! (
               Pointer<A> ) ));
}
#[test]
fn __bindgen_test_layout_Pointer_open0_A_close0_instantiation_1() {
    assert_eq!(::std::mem::size_of::<Pointer<A>>() , 16usize , concat ! (
               "Size of template specialization: " , stringify ! ( Pointer<A>
               ) ));
    assert_eq!(::std::mem::align_of::<Pointer<A>>() , 8usize , concat ! (
               "Alignment of template specialization: " , stringify ! (
               Pointer<A> ) ));
}

Expected Results

Destructor for Pointer is missing.
Same behaviour happens with ordinary c++ shared_ptr.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions