Skip to content

Commit ebd5a6d

Browse files
authored
Fix temporary receivers (#397)
1 parent 202185c commit ebd5a6d

7 files changed

Lines changed: 54 additions & 0 deletions

File tree

‎cpp2rust/converter/converter_lib.cpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,6 +1438,9 @@ bool IsTemporaryObject(const clang::Expr *expr) {
14381438
if (operand != expr) {
14391439
return !operand->isGLValue();
14401440
}
1441+
if (clang::isa<clang::MaterializeTemporaryExpr>(expr->IgnoreImpCasts())) {
1442+
return true;
1443+
}
14411444
return !expr->isLValue();
14421445
}
14431446

‎tests/unit/operator_arithmetic_member.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,6 @@ int main() {
4545
assert((a--).v == 8);
4646
assert(a.v == 7);
4747
assert((++(++a)).v == 9);
48+
assert((S{3} + S{4}).v == 7);
4849
return 0;
4950
}

‎tests/unit/operator_other_member.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,7 @@ int main() {
3333
assert(!z);
3434
Static st;
3535
assert(st(6, 7) == 42);
36+
assert(S{5}() == 5);
37+
assert(S{5}(1, 1) == 7);
3638
return 0;
3739
}

‎tests/unit/out/refcount/operator_arithmetic_member.rs‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,23 @@ fn main_0() -> i32 {
113113
.borrow())
114114
== 9)
115115
);
116+
assert!(
117+
((*({
118+
let _o: Value<S> = Rc::new(RefCell::new(S {
119+
v: Rc::new(RefCell::new(4)),
120+
}));
121+
SImpl::operator_add_pconstS_const(
122+
&Rc::new(RefCell::new(S {
123+
v: Rc::new(RefCell::new(3)),
124+
}))
125+
.as_pointer(),
126+
_o.as_pointer(),
127+
)
128+
})
129+
.v
130+
.borrow())
131+
== 7)
132+
);
116133
return 0;
117134
}
118135
pub trait SImpl {

‎tests/unit/out/refcount/operator_other_member.rs‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,28 @@ fn main_0() -> i32 {
7575
assert!(!({ SImpl::operator__Bool(&z.as_pointer(),) }));
7676
let st: Value<Static> = Rc::new(RefCell::new(<Static>::default()));
7777
assert!((({ Static::operator_call(6, 7,) }) == 42));
78+
assert!(
79+
(({
80+
SImpl::operator_call_const(
81+
&Rc::new(RefCell::new(S {
82+
v: Rc::new(RefCell::new(5)),
83+
}))
84+
.as_pointer(),
85+
)
86+
}) == 5)
87+
);
88+
assert!(
89+
(({
90+
SImpl::operator_call_i32_i32_const(
91+
&Rc::new(RefCell::new(S {
92+
v: Rc::new(RefCell::new(5)),
93+
}))
94+
.as_pointer(),
95+
1,
96+
1,
97+
)
98+
}) == 7)
99+
);
78100
return 0;
79101
}
80102
pub trait SImpl {

‎tests/unit/out/unsafe/operator_arithmetic_member.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ unsafe fn main_0() -> i32 {
8888
(((*(unsafe { S::operator_inc(&mut (*(unsafe { S::operator_inc(&mut a,) })),) })).v)
8989
== (9))
9090
);
91+
assert!(
92+
(((unsafe {
93+
let mut _o: S = S { v: 4 };
94+
S::operator_add_pconstS_const(&S { v: 3 }, &mut _o)
95+
})
96+
.v) == (7))
97+
);
9198
return 0;
9299
}
93100
pub unsafe fn __cpp2rust_init_globals() {}

‎tests/unit/out/unsafe/operator_other_member.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ unsafe fn main_0() -> i32 {
6666
assert!(!(unsafe { S::operator__Bool(&z,) }));
6767
let mut st: Static = <Static>::default();
6868
assert!(((unsafe { Static::operator_call(6, 7,) }) == (42)));
69+
assert!(((unsafe { S::operator_call_const(&S { v: 5 },) }) == (5)));
70+
assert!(((unsafe { S::operator_call_i32_i32_const(&S { v: 5 }, 1, 1,) }) == (7)));
6971
return 0;
7072
}
7173
pub unsafe fn __cpp2rust_init_globals() {}

0 commit comments

Comments
 (0)