Closed ctaggart closed 6 years ago
Thanks for the bug report @ctaggart !
Here is a slightly cleaned up / annotated test case:
// bindgen-flags: --enable-cxx-namespaces -- -std=c++11
// First::sentry and Second::sentry should be emitted as `First_sentry` and
// `Second_sentry`, but instead are both being named just `sentry` which leads
// to compilation errors.
//
// Note: if there is no namespace, then we don't run into problems. Similarly,
// making the `sentry` definitions inline in `First` and `Second`, rather than
// declared inline with out of line definitions, makes the problem go away as
// well.
namespace whatever {
template <typename, typename>
class First {
// Declaration of First::sentry
class sentry;
};
// Definition of First::sentry
template <typename f, typename h>
class First<f, h>::sentry {};
template <typename, typename>
class Second {
// Declaration of Second::sentry
class sentry;
};
// Definition of Second::sentry
template <typename f, typename h>
class Second<f, h>::sentry {};
}
And here are the bindings that get generated:
/* automatically generated by rust-bindgen */
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)]
pub mod root {
#[allow(unused_imports)]
use self::super::root;
pub mod whatever {
#[allow(unused_imports)]
use self::super::super::root;
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct First {
pub _address: u8,
}
#[repr(C)]
#[derive(Debug, Default, Copy)]
pub struct sentry {
pub _address: u8,
}
impl Clone for sentry {
fn clone(&self) -> Self {
*self
}
}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct Second {
pub _address: u8,
}
#[repr(C)]
#[derive(Debug, Default, Copy)]
pub struct sentry {
pub _address: u8,
}
impl Clone for sentry {
fn clone(&self) -> Self {
*self
}
}
}
}
It seems like we're parsing the inner sentry
classes incorrectly, and they don't end up with First
or Second
as their parents.
Here's the IR:
I have a fix over in https://github.com/rust-lang-nursery/rust-bindgen/pull/1049
I tried the fix out and it worked for https://github.com/ctaggart/octh/issues/29.
For Octave bindings, I need to interop with C++ std::string https://github.com/ctaggart/octh/issues/28. Any recommendations of how to do this are appreciated. This is the first issue I'm up against that I'm not sure how to solve. https://github.com/ctaggart/octh/issues/29
Input C/C++ Header
Bindgen Invocation
Actual Results
Expected Results
It compiles.