-
Notifications
You must be signed in to change notification settings - Fork 144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Types with non-type template parameters turn into integers of the wrong size #787
Comments
Thanks for the report.
Any of the integration tests should try to build the resulting C++ code, and even execute it. They each use the |
Here's what
so I'm pretty sure this will turn out to be a limitation of As a first step, I'm reducing this into an even smaller test case. |
Oh, and for completeness, here's what actually goes wrong with the test case added in #787:
|
Here's the typedef char c;
typedef int d;
typedef c uint8_t;
typedef d e;
namespace std {
using ::uint8_t;
template <e> struct f;
typedef f<0> g;
namespace chrono {
template <typename h, typename = typename h::duration> struct i;
using j = g;
template <typename, typename k> struct i {
typedef k duration;
duration l;
};
} // namespace chrono
} // namespace std
struct m {
typedef std::chrono::j duration;
};
struct Class {
int a();
std::chrono::i<m> b();
};
|
Running upstream bindgen
yields #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)]
pub mod root {
#[allow(unused_imports)]
use self::super::root;
pub mod std {
#[allow(unused_imports)]
use self::super::super::root;
pub type g = u8;
pub mod chrono {
#[allow(unused_imports)]
use self::super::super::super::root;
pub type j = root::std::g;
#[repr(C)]
pub struct i<k> {
pub l: root::std::chrono::i_duration<k>,
pub _phantom_0:
::std::marker::PhantomData<::std::cell::UnsafeCell<k>>,
}
pub type i_duration<k> = k;
}
}
#[repr(C)]
pub struct m {
pub _address: u8,
}
pub type m_duration = root::std::chrono::j;
#[repr(C)]
pub struct Class {
pub _address: u8,
}
extern "C" {
#[link_name = "\u{1}_ZN5Class1aEv"]
pub fn Class_a(this: *mut root::Class) -> ::std::os::raw::c_int;
}
extern "C" {
#[link_name = "\u{1}_ZN5Class1bEv"]
pub fn Class_b(this: *mut root::Class) -> u8;
}
impl Class {
#[inline]
pub unsafe fn a(&mut self) -> ::std::os::raw::c_int {
Class_a(self)
}
#[inline]
pub unsafe fn b(&mut self) -> u8 {
Class_b(self)
}
}
} confirming that this appears to be normal |
Some manual minimization gives this: namespace chrono {
template <typename h, typename = typename h::duration> struct i;
template <int> struct f;
typedef f<0> j;
template <typename, typename k> struct i {
typedef k duration;
duration l;
};
} // namespace chrono
struct m {
typedef chrono::j duration;
};
struct Class {
int a();
chrono::i<m> b();
}; |
After poking into bindgen a bit, I think the bugs there are rust-lang/rust-bindgen#362 and then rust-lang/rust-bindgen#869 in the fallback "opaque blob" codegen. The former looks hard to fix (it mentions libclang changes). Fixing the latter is still going to confuse autocxx into generating C++ code that doesn't compile, but I think that's a duplicate of #687. |
Looks like the limitation around non-type template parameters means bindgen doesn't have any way to even get the size of the type, which pretty much prevents any chance of making this fully work. Best case right now looks like bindgen getting smarter about omitting types where it can't find the size, instead of guessing their size is |
std::chrono::time_point
turns into an integeru8
u8
If I have a C++ class with a member function that interacts with a
std::chrono::time_point
instantiation by value, autocxx generates wrappers that replacetime_point
with an integer type. My full codebase ends up withuint64_t
, my simplified example ends up withuint8_t
, not sure why they're different. This results in C++ wrappers that don't compile, so I can't even use other member functions that do have signatures autocxx can handle.Expected Behavior
Skip generating wrappers for these methods, like other forms of unhandled things.
Actual Behavior
Generated C++ code that doesn't compile.
Steps to Reproduce the Problem
include_cpp!
in some .rs file,generate!("Class")
.I don't see any integration tests which try compiling the generated C++ code I can add this to and submit a PR, let me know if there's a good way to do that.
Specifications
The text was updated successfully, but these errors were encountered: