rust-lang / rust-lang/rust-bindgen

Wrong constructor on MSVC (default constructor closure)

Open
#661 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

To confirm, it looks like that extra constructor case is the "default
constructor closure," which is generated when dllexporting a default
constructor that requires some extra code to call, and the
clang_Cursor_getCXXManglings solution handles it incorrectly.

For example, this code generates two constructors, with symbols
??0Foo@@QEAA@H@Z (public: __cdecl Foo::Foo(int)) and ??_FFoo@@QEAAXXZ
(public: void __cdecl Foo::\default constructor closure'(void)`).

struct __declspec(dllexport) Foo {
    Foo(int x = 3);
};

Bindgen declares the first but gives it the link_name of the second:

extern "C" {
    #[link_name = "??_FFoo@@QEAAXXZ"]
    pub fn Foo_Foo(this: *mut Foo, x: ::std::os::raw::c_int);
}

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

Reproduce the reported MSVC case using the shown dllexported C++ Foo with a default argument, then inspect how clang_Cursor_getCXXManglings is used for constructor declarations. Compare the generated Foo_Foo declaration with the two symbols described in the issue; done means the declared constructor is linked to the actual constructor symbol rather than the default constructor closure.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, rust
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.