Skip to content

Associated types not resolved to concrete type #1924

@adetaylor

Description

@adetaylor

Input C/C++ Header

struct InnerType {
    typedef int related_type;
};

template <typename ContainedType> class Container {
public:
    typedef typename ContainedType::related_type contents;
    contents contents_;
};

typedef Container<InnerType> Concrete;

struct LaterContainingType {
    Concrete contents;
};

Bindgen Invocation

    let bindings = bindgen::Builder::default()
        .header("wrapper.hpp")
        .clang_args(&["-x", "c++", "-std=c++14"])
        .layout_tests(false)
        .whitelist_type("LaterContainingType")
        .parse_callbacks(Box::new(bindgen::CargoCallbacks))
        .generate()
        .expect("Unable to generate bindings");

Rust code

#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]

include!(concat!(env!("OUT_DIR"), "/bindings.rs"));

fn main() {
    Concrete { contents_: 32 };
}

Actual Results

$ cargo build
   Compiling bindgen-test-case v0.1.0
error[E0308]: mismatched types
 --> src/main.rs:8:27
  |
8 |     Concrete { contents_: 32 };
  |                           ^^ expected array `[u8; 0]`, found integer

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
error: could not compile `bindgen-test-case`

Expected Results

I'd expect the type of contents_ to be a c_int.

Other notes

Perhaps this counts as the "traits templates" situation listed under the recorded C++ limitations but, as it doesn't involve any nasty SFINAE magic I am hoping this may be possible.

Thanks for bindgen, it's amazing! Apologies if this is a duplicate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions