From 0ecd05a9bf0096d5c05a44e82d4221cc291a9ef5 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Wed, 29 Jul 2020 16:32:03 -0700 Subject: [PATCH] Include when placement new is used --- gen/src/include.rs | 4 ++++ gen/src/write.rs | 4 ++++ include/cxx.h | 1 + 3 files changed, 9 insertions(+) diff --git a/gen/src/include.rs b/gen/src/include.rs index 0ed76ac1..4309c9ce 100644 --- a/gen/src/include.rs +++ b/gen/src/include.rs @@ -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 ")?; } + if self.new { + writeln!(f, "#include ")?; + } if self.string { writeln!(f, "#include ")?; } diff --git a/gen/src/write.rs b/gen/src/write.rs index 2cf9faf6..46b6151c 100644 --- a/gen/src/write.rs +++ b/gen/src/write.rs @@ -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 and UniquePtr>. 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); diff --git a/include/cxx.h b/include/cxx.h index 9f4fb476..f211b3be 100644 --- a/include/cxx.h +++ b/include/cxx.h @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include