rust-lang / rust-lang/rust-bindgen

bindgen does not generate destructors if the class inherits a virtual destructor

Open
#1,843 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-C++ bug
Dominant language
Rust
Stars
5.3k
Forks
829
Avg merge
1d 1h
Merged PRs (30d)
15

Description

Input C/C++ Header
class Parent {
public:
	virtual ~Parent();
};
class Child: Parent {
public:
	Child();
	~Child();
};
Bindgen Invocation
bindgen::Builder::default()
        .header("wrapper.hpp")
        .parse_callbacks(Box::new(bindgen::CargoCallbacks))
        .clang_arg("-x")
        .clang_arg("c++")
        .generate()
Actual Results
... more code...
impl Child {
    #[inline]
    pub unsafe fn new() -> Self {
        let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit();
        Child_Child(__bindgen_tmp.as_mut_ptr());
        __bindgen_tmp.assume_init()
    }
}
extern "C" {
    #[link_name = "\u{1}_ZN5ChildD1Ev"]
    pub fn Child_Child_destructor(this: *mut Child);
}
Expected Results

There should be a "pub unsafe fn destruct(&mut self)" in the "impl Child" section.
Note: In C++, first the virtual Parent destructor is callend then the Child destructor.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the wrapper.hpp example and the bindgen::Builder invocation, then inspect how the generated impl Child handles the C++ destructor. Compare the generated destructor declaration with the expected pub unsafe fn destruct(&mut self), including the inherited virtual Parent destructor behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, rust
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.