Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cpp2rust/converter/converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2010,7 +2010,7 @@ Converter::CallInfo Converter::CollectCallInfo(clang::CallExpr *expr) {
: Kind::Hoisted,
};
bool is_materialize = clang::isa<clang::MaterializeTemporaryExpr>(arg);
if (is_materialize && ca.param_type->isReferenceType()) {
if (NeedsRefBindingTemp(ctx_, arg, ca.param_type)) {
ca.kind = Kind::Materialized;
} else if (is_materialize) {
ca.kind = Kind::Inline;
Expand Down
23 changes: 23 additions & 0 deletions tests/unit/out/refcount/size_t_ssize_t.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ pub fn take_ulong_1(mut x: u64) -> u64 {
pub fn sub_signed_2(mut a: isize, mut b: isize) -> isize {
return (a - b);
}
pub fn next_size_3(x: Ptr<usize>) -> usize {
return (x.read()).wrapping_add(1_usize);
}
pub fn next_ulong_4(x: Ptr<u64>) -> u64 {
return (x.read()).wrapping_add(1_u64);
}
pub fn main() {
__cpp2rust_init_globals();
std::process::exit(main_0());
Expand Down Expand Up @@ -202,6 +208,23 @@ fn main_0() -> i32 {
Rc::new(RefCell::new(1.try_into().expect("failed conversion"))),
)));
assert!(((*(*pr.borrow()).0.borrow()) == 21_u64));
let ref_ul: Value<u64> = Rc::new(RefCell::new(5_u64));
let ref_sz: Value<usize> = Rc::new(RefCell::new(7_usize));
assert!(
(({
let _x: Value<usize> = Rc::new(RefCell::new(((*ref_ul.borrow()) as usize)));
next_size_3(_x.as_pointer())
}) == 6_usize)
);
assert!(
(({
let _x: Value<u64> = Rc::new(RefCell::new(((*ref_sz.borrow()) as u64)));
next_ulong_4(_x.as_pointer())
}) == 8_u64)
);
assert!((({ next_size_3(ref_sz.as_pointer(),) }) == 8_usize));
assert!(((*ref_ul.borrow()) == 5_u64));
assert!(((*ref_sz.borrow()) == 7_usize));
return 0;
}
pub fn __cpp2rust_init_globals() {}
23 changes: 23 additions & 0 deletions tests/unit/out/unsafe/size_t_ssize_t.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ pub unsafe fn take_ulong_1(mut x: u64) -> u64 {
pub unsafe fn sub_signed_2(mut a: isize, mut b: isize) -> isize {
return ((a) - (b));
}
pub unsafe fn next_size_3(x: *const usize) -> usize {
return (*x).wrapping_add(1_usize);
}
pub unsafe fn next_ulong_4(x: *const u64) -> u64 {
return (*x).wrapping_add(1_u64);
}
pub fn main() {
unsafe {
__cpp2rust_init_globals();
Expand Down Expand Up @@ -188,6 +194,23 @@ unsafe fn main_0() -> i32 {
assert!(((mins[(2) as usize]) == (2_usize)));
let mut pr: (u64, i32) = ((sz as u64).into(), 1.into());
assert!(((pr.0) == (21_u64)));
let mut ref_ul: u64 = 5_u64;
let mut ref_sz: usize = 7_usize;
assert!(
((unsafe {
let mut _x: usize = (ref_ul as usize);
next_size_3(&mut _x)
}) == (6_usize))
);
assert!(
((unsafe {
let mut _x: u64 = (ref_sz as u64);
next_ulong_4(&mut _x)
}) == (8_u64))
);
assert!(((unsafe { next_size_3(&ref_sz,) }) == (8_usize)));
assert!(((ref_ul) == (5_u64)));
assert!(((ref_sz) == (7_usize)));
return 0;
}
pub unsafe fn __cpp2rust_init_globals() {}
12 changes: 12 additions & 0 deletions tests/unit/size_t_ssize_t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ static unsigned long take_ulong(unsigned long x) { return x; }

static ssize_t sub_signed(ssize_t a, ssize_t b) { return a - b; }

static size_t next_size(const size_t &x) { return x + 1; }

static unsigned long next_ulong(const unsigned long &x) { return x + 1; }

int main() {
size_t n = sizeof(int) + 4;
assert(n == sizeof(int) + 4);
Expand Down Expand Up @@ -107,5 +111,13 @@ int main() {

std::pair<std::size_t, int> pr(sz, 1);
assert(pr.first == 21);

unsigned long ref_ul = 5;
size_t ref_sz = 7;
assert(next_size(ref_ul) == 6);
assert(next_ulong(ref_sz) == 8);
assert(next_size(ref_sz) == 8);
assert(ref_ul == 5);
assert(ref_sz == 7);
return 0;
}
Loading