rust-lang / rust-lang/rust-bindgen

C++ class method pointer treated as C function pointer

Open
#1,894 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug help wanted
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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.