Constructors depend on memmovable fields or RVO.
emilio opened this issue · 1 comments
emilio commented
jsgf commented
This does seem to be a problem in practice.
This test fails:
// TestType.h
struct TestType {
TestType *self;
TestType();
bool isvalid() const;
};
// TestType.cpp
TestType::TestType() {
self = this;
}
bool TestType::isvalid() const {
return self == this;
}
// test.rs
fn test() {
let v = unsafe { mem::uninitialized() };
v = unsafe { TestType::new() };
assert!(unsafe { v.isvalid() }); // Fails
}
I think bindgen should be generating a placement new method:
impl TestType {
unsafe fn new_ptr(this: *mut Self) { TestType_TestType(this) }
}