Skip to content
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

Constructors depend on memmovable fields or RVO. #607

Open
emilio opened this issue Apr 3, 2017 · 1 comment
Open

Constructors depend on memmovable fields or RVO. #607

emilio opened this issue Apr 3, 2017 · 1 comment

Comments

@emilio
Copy link
Contributor

emilio commented Apr 3, 2017

As @jsgf points out in #556, the current code generated for constructors relies on RVO, or requires memmovable fields.

@jsgf
Copy link
Contributor

jsgf commented Apr 21, 2017

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) }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants