rust-lang / rust-lang/rust-bindgen

bindings fail to compile with "the name ... is defined multiple times"

Open
#1,911 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

C++ header

template <typename> class a {
  typedef int b;
  a &c(long, b);
};
template <> a<char> &a<char>::c(long, b);
template <> a<wchar_t> &a<wchar_t>::c(long, b);

bindgen command

bindgen test-case-2.hpp -- -x c++

Generated bindings

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct a {
    pub _address: u8,
}
pub type a_b = ::std::os::raw::c_int;
pub type b = ::std::os::raw::c_int;
pub type b = ::std::os::raw::c_int;

rustc errors with

error[E0428]: the name `b` is defined multiple times

Expected Results

I would expect that bindgen would error if this c++ header is not usable with bindgen or the bindings would compile and it is usable. Sorry my c++ is pretty poor, so I can't make a more informed statement.

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 by running the shown bindgen command against test-case-2.hpp and inspect the generated Rust aliases. Trace how the two C++ specializations produce duplicate b definitions; done means the bindings compile without duplicate names or bindgen reports a clear unsupported-input error.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, rust
Domain
tooling
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.