Open fitzgen opened 7 years ago
I don't know how could we possibly fix this without monomorphization tbh.
I'd also expect this to fail:
class Foo {
virtual void vtable();
};
template<typename T>
class Bar : public T {};
Mainly, the code we should generate for the template depends on the actual argument.
Mainly, the code we should generate for the template depends on the actual argument.
I would hope that libclang would give us a layout for a concrete instantiation, though. Haven't dug into it yet, however.
Cleaned up test case:
// bindgen-flags: -- -std=c++14
class Base {};
template <class BaseT>
class CallArgsBase : BaseT {
int *c;
unsigned d;
};
class CallArgs : CallArgsBase<Base> {};
I'm not sure what is going on here and why the expected layout is size 16. Does C++ allow zero-sized base classes as long as the derived class is not zero sized? If so, then I think we're hosed.
Does C++ allow zero-sized base classes as long as the derived class is not zero sized?
Yes
If so, then I think we're hosed.
and yes
I don't know how could we possibly fix this without monomorphization tbh.
I'd also expect this to fail:
Filed https://github.com/servo/rust-bindgen/issues/851 for this version
With non-Copy
types in unions, or a cosnt-fn
version of std::mem::size_of
, we could do this:
#![feature(untagged_unions)]
use std::mem;
struct Inherits<T> {
_base: AtLeastOneByte<T>,
}
union AtLeastOneByte<T> {
t: T,
_address: u8,
}
struct SizedFoo {
x: usize,
y: usize,
}
struct UnsizedBar;
fn main() {
println!("size of Inherits<SizedFoo> = {}", mem::size_of::<Inherits<SizedFoo>>());
println!("size of Inherits<UnsizedBar> = {}", mem::size_of::<Inherits<UnsizedBar>>());
}
Emits:
size of Inherits<SizedFoo> = 16
size of Inherits<UnsizedBar> = 1
Although we would need to actually emit two versions of Inherits
: One for when it is used as a base class, and another for when it is not. Only the latter would apply AtLeastOneByte
.
Input C/C++ Header
Bindgen Invokation
Actual Results
Compiles into this:
And results in this layout test failure:
Expected Results
Maybe opaque blobs, but never any layout test failures.