Include <new> when placement new is used

This commit is contained in:
David Tolnay 2020-07-29 16:32:03 -07:00
parent 2b87b16679
commit 0ecd05a9bf
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
3 changed files with 9 additions and 0 deletions

View File

@ -56,6 +56,7 @@ pub struct Includes {
pub cstring: bool,
pub exception: bool,
pub memory: bool,
pub new: bool,
pub string: bool,
pub type_traits: bool,
pub utility: bool,
@ -106,6 +107,9 @@ impl Display for Includes {
if self.memory {
writeln!(f, "#include <memory>")?;
}
if self.new {
writeln!(f, "#include <new>")?;
}
if self.string {
writeln!(f, "#include <string>")?;
}

View File

@ -149,11 +149,13 @@ fn write_include_cxxbridge(out: &mut OutFile, apis: &[Api], types: &Types) {
for ty in types {
match ty {
Type::RustBox(_) => {
out.include.new = true;
out.include.type_traits = true;
needs_rust_box = true;
}
Type::RustVec(_) => {
out.include.array = true;
out.include.new = true;
out.include.type_traits = true;
needs_rust_vec = true;
}
@ -463,6 +465,7 @@ fn write_cxx_function_shim(out: &mut OutFile, efn: &ExternFn, types: &Types) {
write!(out, " ");
}
if indirect_return {
out.include.new = true;
write!(out, "new (return$) ");
write_indirect_return_type(out, efn.ret.as_ref().unwrap());
write!(out, "(");
@ -1149,6 +1152,7 @@ fn write_unique_ptr(out: &mut OutFile, ident: &Ident, types: &Types) {
// Shared by UniquePtr<T> and UniquePtr<CxxVector<T>>.
fn write_unique_ptr_common(out: &mut OutFile, ty: &Type, types: &Types) {
out.include.new = true;
out.include.utility = true;
let inner = to_typename(&out.namespace, ty);
let instance = to_mangled(&out.namespace, ty);

View File

@ -4,6 +4,7 @@
#include <cstdint>
#include <exception>
#include <iosfwd>
#include <new>
#include <string>
#include <type_traits>
#include <utility>