rust-lang / rust-lang/rust-bindgen

Generated bindings don't compile

Open
#1,609 2 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

bindgen 0.51.0

Input C/C++ Header
template <class, class Compare = int> class a { Compare b; };
namespace AZ {
template <class> struct c;
template <class e> struct EBusRouterPolicy {
  using d = c<typename e::f>;
  typedef a<d> Container;
};
} // namespace AZ
Bindgen Invocation
$ bindgen __bindgen.ii -- --std=c++14
Actual Results
/* automatically generated by rust-bindgen */

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct a<Compare> {
    pub b: Compare,
    pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<Compare>>,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct AZ_c {
    pub _address: u8,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct AZ_EBusRouterPolicy {
    pub _address: u8,
}
pub type AZ_EBusRouterPolicy_d = AZ_c;
pub type AZ_EBusRouterPolicy_Container = a<Compare>;

Compile above with rustc --crate-type lib:

error[E0412]: cannot find type `Compare` in this scope
  --> bindgen.rs:20:44
   |
20 | pub type AZ_EBusRouterPolicy_Container = a<Compare>;
   |                                            ^^^^^^^ not found in this scope
Expected Results

Last line of bindings should probably be:

pub type AZ_EBusRouterPolicy_Container<Compare> = a<Compare>;

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 report with the supplied C++ header and bindgen __bindgen.ii -- --std=c++14, then compile the generated bindings with rustc --crate-type lib. Trace how the templated Container alias is emitted; done means the generated alias retains its template parameter and the bindings compile without the unresolved Compare error.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, rust
Domain
compilers, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.