rust-lang / rust-lang/rust-bindgen
C++ class method pointer treated as C function pointer
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 5.3k
- Forks
- 829
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 15
Description
Input C/C++ Header
class Thing {
void (Thing::*method_ptr)(void);
};
Bindgen Invocation
$ bindgen header.hpp -o src/bindings.rs
Actual Results
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Thing {
pub method_ptr: ::std::option::Option<unsafe extern "C" fn()>,
}
Expected Results
From C++, sizeof(Thing::method_ptr) == 16, however from Rust it's 8 (which appropriately causes the generated test for the size of Thing to fail). I'd expect either to get an error on binding generation if this isn't supported, or a generated method_ptr field with the same size as the C++ equivalent. This is with bindgen 0.55.1 on x86-64.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the header.hpp reproduction and the bindgen invocation, then inspect the generated src/bindings.rs and the generated Thing size test. Trace how C++ member-function-pointer fields are represented and determine whether unsupported input should fail generation or preserve the field's C++ layout. Done means the incorrect 8-byte representation is no longer emitted without an explicit failure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, rust
- Domain
- compilers, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100