diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 35e6275ee5..1fcc8b6755 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -5476,7 +5476,8 @@ std::string Converter::ConvertPlaceholder(clang::Expr *expr, clang::Expr *arg, } if (ph_ctx.access == TranslationRule::Access::kTake) { - if (clang::isa(arg)) { + if (clang::isa(arg) || + arg->getType().isTriviallyCopyableType(ctx_)) { return ConvertFreshRValue(arg); } return ConvertTake(arg); diff --git a/tests/unit/out/refcount/vector.rs b/tests/unit/out/refcount/vector.rs index 3ef09b0a87..480b278238 100644 --- a/tests/unit/out/refcount/vector.rs +++ b/tests/unit/out/refcount/vector.rs @@ -466,6 +466,23 @@ fn main_0() -> i32 { && ({ (*v10.borrow())[1_usize] } == 7) }) ); + let mut v12: Vec = Vec::new(); + let moved: Value = Rc::new(RefCell::new(5)); + { + let __a1 = ({ (*moved.borrow()) }); + v12.push(__a1) + }; + assert!(({ (v12[0_usize] == 5) && ((*moved.borrow()) == 5) })); + let mut v13: Vec> = Vec::new(); + let mut moved_ptr: Ptr = (moved.as_pointer()); + { + let __a1 = (moved_ptr).clone(); + v13.push(__a1) + }; + assert!( + (v13[0_usize] == (moved.as_pointer())) + && ({ (moved_ptr).clone() } == { (moved.as_pointer()) }) + ); return 0; } pub trait FooImpl { diff --git a/tests/unit/out/unsafe/vector.rs b/tests/unit/out/unsafe/vector.rs index c08797fd0f..befb1a9a4e 100644 --- a/tests/unit/out/unsafe/vector.rs +++ b/tests/unit/out/unsafe/vector.rs @@ -362,6 +362,22 @@ unsafe fn main_0() -> i32 { assert!( (((foo.a.len()) == (1_usize)) && ((foo.a[(0_usize)]) == (4))) && ((v10[(1_usize)]) == (7)) ); + let mut v12: Vec = Vec::new(); + let mut moved: i32 = 5; + { + let __a1 = moved; + v12.push(__a1) + }; + assert!(((v12[(0_usize)]) == (5)) && ((moved) == (5))); + let mut v13: Vec<*mut i32> = Vec::new(); + let mut moved_ptr: *mut i32 = (&mut moved as *mut i32); + { + let __a1 = moved_ptr; + v13.push(__a1) + }; + assert!( + ((v13[(0_usize)]) == (&mut moved as *mut i32)) && ((moved_ptr) == (&mut moved as *mut i32)) + ); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/vector.cpp b/tests/unit/vector.cpp index 2f907cca43..5063816bfc 100644 --- a/tests/unit/vector.cpp +++ b/tests/unit/vector.cpp @@ -1,4 +1,5 @@ #include +#include #include struct S { @@ -177,5 +178,14 @@ int main() { assert(foo.a.size() == 2 && foo.a[1] == 7 && foo.b[0] == 5); exchange(foo.a, v10); assert(foo.a.size() == 1 && foo.a[0] == 4 && v10[1] == 7); + + std::vector v12; + int moved = 5; + v12.push_back(std::move(moved)); + assert(v12[0] == 5 && moved == 5); + std::vector v13; + int *moved_ptr = &moved; + v13.push_back(std::move(moved_ptr)); + assert(v13[0] == &moved && moved_ptr == &moved); return 0; }