Skip to content

Commit 4caede6

Browse files
authored
Merge pull request #239 from dtolnay/new
Include <new> when placement new is used
2 parents 2b87b16 + 0ecd05a commit 4caede6

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

gen/src/include.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ pub struct Includes {
5656
pub cstring: bool,
5757
pub exception: bool,
5858
pub memory: bool,
59+
pub new: bool,
5960
pub string: bool,
6061
pub type_traits: bool,
6162
pub utility: bool,
@@ -106,6 +107,9 @@ impl Display for Includes {
106107
if self.memory {
107108
writeln!(f, "#include <memory>")?;
108109
}
110+
if self.new {
111+
writeln!(f, "#include <new>")?;
112+
}
109113
if self.string {
110114
writeln!(f, "#include <string>")?;
111115
}

gen/src/write.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,13 @@ fn write_include_cxxbridge(out: &mut OutFile, apis: &[Api], types: &Types) {
149149
for ty in types {
150150
match ty {
151151
Type::RustBox(_) => {
152+
out.include.new = true;
152153
out.include.type_traits = true;
153154
needs_rust_box = true;
154155
}
155156
Type::RustVec(_) => {
156157
out.include.array = true;
158+
out.include.new = true;
157159
out.include.type_traits = true;
158160
needs_rust_vec = true;
159161
}
@@ -463,6 +465,7 @@ fn write_cxx_function_shim(out: &mut OutFile, efn: &ExternFn, types: &Types) {
463465
write!(out, " ");
464466
}
465467
if indirect_return {
468+
out.include.new = true;
466469
write!(out, "new (return$) ");
467470
write_indirect_return_type(out, efn.ret.as_ref().unwrap());
468471
write!(out, "(");
@@ -1149,6 +1152,7 @@ fn write_unique_ptr(out: &mut OutFile, ident: &Ident, types: &Types) {
11491152

11501153
// Shared by UniquePtr<T> and UniquePtr<CxxVector<T>>.
11511154
fn write_unique_ptr_common(out: &mut OutFile, ty: &Type, types: &Types) {
1155+
out.include.new = true;
11521156
out.include.utility = true;
11531157
let inner = to_typename(&out.namespace, ty);
11541158
let instance = to_mangled(&out.namespace, ty);

include/cxx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <cstdint>
55
#include <exception>
66
#include <iosfwd>
7+
#include <new>
78
#include <string>
89
#include <type_traits>
910
#include <utility>

0 commit comments

Comments
 (0)