diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index fd4a3b5c30..6a07306b88 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -3136,6 +3136,11 @@ bool Converter::ConvertIncAndDec(clang::UnaryOperator *expr) { MarkFresh(); return true; } + bool deref_prefix = expr->isPrefix() && !isVoid(); + PushParen paren(*this, deref_prefix); + if (deref_prefix) { + StrCat(token::kStar); + } { PushExprKind push(*this, ExprKind::LValue); Convert(expr->getSubExpr()); diff --git a/cpp2rust/converter/models/boxed_vars.cpp b/cpp2rust/converter/models/boxed_vars.cpp index 4e78ce6b00..4edc4707a6 100644 --- a/cpp2rust/converter/models/boxed_vars.cpp +++ b/cpp2rust/converter/models/boxed_vars.cpp @@ -255,7 +255,8 @@ class AddressTakenVisitor } bool VisitUnaryOperator(clang::UnaryOperator *expr) { - if (expr->isIncrementDecrementOp()) { + if (expr->isIncrementDecrementOp() && + (expr->isPostfix() || expr->isPRValue())) { AddValueUse(expr->getSubExpr(), /*write=*/true); } return true; @@ -392,6 +393,11 @@ class AddressTakenVisitor // without making a pointer to it. void AddValueUse(const clang::Expr *expr, bool write = false) { expr = IgnoreNoOpCasts(IgnoreTransparentStdCall(expr)->IgnoreParens()); + if (auto *op = clang::dyn_cast(expr); + op && op->isPrefix() && op->isIncrementDecrementOp()) { + AddValueUse(op->getSubExpr(), /*write=*/true); + return; + } // The value of a conditional lvalue is the value of either operand; it is // written through a pointer to the operand. if (auto *cond = clang::dyn_cast(expr)) { @@ -423,6 +429,14 @@ class AddressTakenVisitor if (auto *cleanups = clang::dyn_cast(expr)) { expr = cleanups->getSubExpr()->IgnoreParens(); } + if (auto *op = clang::dyn_cast(expr); + op && op->isIncrementDecrementOp()) { + AddValueUse(op->getSubExpr(), /*write=*/true); + } else if (auto *comma = clang::dyn_cast(expr); + comma && comma->getOpcode() == clang::BO_Comma) { + AddDiscardedUse(comma->getRHS()); + } + auto *binary = clang::dyn_cast(expr); if (!binary) { return; diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index 9916a2ee43..fd5ccd1765 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -925,22 +925,51 @@ bool ConverterRefCount::ConvertIncAndDec(clang::UnaryOperator *expr) { if (expr->isPrefix() && isAddrOf()) { auto ptr = ConvertFreshObject(sub_expr); auto name = NewTempName(); - StrCat( - std::format("{{ let {0} = {1}; {0}.with_mut(|__v| __v.{2}()); {0} }}", - name, ptr, method)); + StrCat(std::format( + "{{ let {0} = {1}; {0}.with_mut(|__v| {{ __v.{2}(); }}); {0} }}", name, + ptr, method)); MarkFresh(); return true; } + bool is_prefix = expr->isPrefix(); auto str = ConvertLValue(sub_expr); if (!pending_deref_.empty()) { - StrCat(pending_deref_.take(), ".with_mut(|__v| __v.", method, "())"); + bool fresh = pending_deref_.is_fresh(); + auto ptr = pending_deref_.take(); + if (!is_prefix) { + StrCat(ptr, ".with_mut(|__v| __v.", method, "())"); + } else if (isVoid()) { + StrCat(ptr, ".with_mut(|__v| { __v.", method, "(); })"); + } else if (isLValue()) { + auto name = NewTempName(); + pending_deref_.set(std::format("{{ let {0} = {1}{2}; {0}.with_mut(|__v| " + "{{ __v.{3}(); }}); {0} }}", + name, ptr, fresh ? "" : ".clone()", + method), + /*fresh=*/true); + return true; + } else { + StrCat(ptr, ".with_mut(|__v| __v.", method, "().clone())"); + } } else if (!isVoid() && clang::isa(sub_expr->IgnoreParens()) && !IsUnboxedPlace(sub_expr)) { // The struct is borrowed in a block, which ends the borrow before the // result is used, e.g., to write through a pointer into the struct. - StrCat(std::format("{{ {}.{}() }}", str, method)); + if (!is_prefix) { + StrCat(std::format("{{ {}.{}() }}", str, method)); + } else if (isLValue()) { + StrCat(std::format("(*{}.{}())", str, method)); + } else { + StrCat(std::format("{{ {}.{}().clone() }}", str, method)); + } + } else if (is_prefix && !isVoid()) { + StrCat(std::format("(*{}.{}())", str, method)); + if (!isLValue()) { + SetValueFreshness(expr->getType()); + return true; + } } else { StrCat(str, '.', method, "()"); } diff --git a/docs/src/runtime/inc-dec.md b/docs/src/runtime/inc-dec.md index 75133de911..34bfe1ee21 100644 --- a/docs/src/runtime/inc-dec.md +++ b/docs/src/runtime/inc-dec.md @@ -6,14 +6,14 @@ statement, so the `inc` and `dec` modules define one trait per operator form: ```rust pub trait PostfixInc { fn postfix_inc(&mut self) -> Self; } -pub trait PrefixInc { fn prefix_inc(&mut self) -> Self; } +pub trait PrefixInc { fn prefix_inc(&mut self) -> &mut Self; } pub trait PostfixDec { fn postfix_dec(&mut self) -> Self; } -pub trait PrefixDec { fn prefix_dec(&mut self) -> Self; } +pub trait PrefixDec { fn prefix_dec(&mut self) -> &mut Self; } ``` Each method updates the value in place and returns what the C expression evaluates to: the postfix forms return a copy of the old value, the prefix forms -the new one. +a mutable reference to the updated operand, which is an lvalue in C++. ```c int x = 0; diff --git a/libcc2rs/src/dec.rs b/libcc2rs/src/dec.rs index 1f5caeb3dd..e7b170540e 100644 --- a/libcc2rs/src/dec.rs +++ b/libcc2rs/src/dec.rs @@ -32,16 +32,16 @@ macro_rules! postfix_wrap_dec_impl { } pub trait PrefixDec { - fn prefix_dec(&mut self) -> Self; + fn prefix_dec(&mut self) -> &mut Self; } macro_rules! prefix_nowrap_dec_impl { ($($type:ty),*) => { $(impl PrefixDec for $type { #[inline] - fn prefix_dec(&mut self) -> Self { + fn prefix_dec(&mut self) -> &mut Self { *self -= 1 as $type; - *self + self } })* }; @@ -51,9 +51,9 @@ macro_rules! prefix_wrap_dec_impl { ($($type:ty),*) => { $(impl PrefixDec for $type { #[inline] - fn prefix_dec(&mut self) -> Self { + fn prefix_dec(&mut self) -> &mut Self { *self = self.wrapping_sub(1 as $type); - *self + self } })* }; @@ -98,22 +98,22 @@ pub trait UnsafePrefixDec { /// # Safety /// This function decrements a pointer and returns the new value. /// The caller must ensure the pointer is valid and doesn't underflow. - unsafe fn prefix_dec(&mut self) -> Self; + unsafe fn prefix_dec(&mut self) -> &mut Self; } impl UnsafePrefixDec for *const T { #[inline] - unsafe fn prefix_dec(&mut self) -> Self { + unsafe fn prefix_dec(&mut self) -> &mut Self { unsafe { *self = self.offset(-1) } - *self + self } } impl UnsafePrefixDec for *mut T { #[inline] - unsafe fn prefix_dec(&mut self) -> Self { + unsafe fn prefix_dec(&mut self) -> &mut Self { unsafe { *self = self.offset(-1) } - *self + self } } @@ -131,7 +131,7 @@ mod tests { #[test] fn test_prefix_dec() { let mut x = 10; - assert_eq!(x.prefix_dec(), 9); + assert_eq!(*x.prefix_dec(), 9); assert_eq!(x, 9); } @@ -152,7 +152,7 @@ mod tests { let y = &x as *const i32; let mut z = &x as *const i32; unsafe { - assert_eq!(z.prefix_dec(), y.offset(-1)); + assert_eq!(*z.prefix_dec(), y.offset(-1)); assert_eq!(z, y.offset(-1)); } } diff --git a/libcc2rs/src/inc.rs b/libcc2rs/src/inc.rs index f4701b4b5b..ac9a782dbe 100644 --- a/libcc2rs/src/inc.rs +++ b/libcc2rs/src/inc.rs @@ -32,16 +32,16 @@ macro_rules! postfix_wrap_inc_impl { } pub trait PrefixInc { - fn prefix_inc(&mut self) -> Self; + fn prefix_inc(&mut self) -> &mut Self; } macro_rules! prefix_nowrap_inc_impl { ($($type:ty),*) => { $(impl PrefixInc for $type { #[inline] - fn prefix_inc(&mut self) -> Self { + fn prefix_inc(&mut self) -> &mut Self { *self += 1 as $type; - *self + self } })* }; @@ -51,9 +51,9 @@ macro_rules! prefix_wrap_inc_impl { ($($type:ty),*) => { $(impl PrefixInc for $type { #[inline] - fn prefix_inc(&mut self) -> Self { + fn prefix_inc(&mut self) -> &mut Self { *self = self.wrapping_add(1 as $type); - *self + self } })* }; @@ -98,22 +98,22 @@ pub trait UnsafePrefixInc { /// # Safety /// This function increments a pointer and returns the new value. /// The caller must ensure the pointer is valid and doesn't overflow. - unsafe fn prefix_inc(&mut self) -> Self; + unsafe fn prefix_inc(&mut self) -> &mut Self; } impl UnsafePrefixInc for *const T { #[inline] - unsafe fn prefix_inc(&mut self) -> Self { + unsafe fn prefix_inc(&mut self) -> &mut Self { unsafe { *self = self.offset(1) } - *self + self } } impl UnsafePrefixInc for *mut T { #[inline] - unsafe fn prefix_inc(&mut self) -> Self { + unsafe fn prefix_inc(&mut self) -> &mut Self { unsafe { *self = self.offset(1) } - *self + self } } @@ -131,7 +131,7 @@ mod tests { #[test] fn test_prefix_inc() { let mut x = 10; - assert_eq!(x.prefix_inc(), 11); + assert_eq!(*x.prefix_inc(), 11); assert_eq!(x, 11); } @@ -152,7 +152,7 @@ mod tests { let y = &x as *const i32; let mut z = &x as *const i32; unsafe { - assert_eq!(z.prefix_inc(), y.offset(1)); + assert_eq!(*z.prefix_inc(), y.offset(1)); assert_eq!(z, y.offset(1)); } } diff --git a/libcc2rs/src/rc.rs b/libcc2rs/src/rc.rs index 4231874d94..787697b78b 100644 --- a/libcc2rs/src/rc.rs +++ b/libcc2rs/src/rc.rs @@ -1444,17 +1444,17 @@ impl PostfixDec for Ptr { impl PrefixInc for Ptr { #[inline] - fn prefix_inc(&mut self) -> Self { + fn prefix_inc(&mut self) -> &mut Self { self.offset = self.offset.wrapping_add(self.elem_step()); - self.clone() + self } } impl PrefixDec for Ptr { #[inline] - fn prefix_dec(&mut self) -> Self { + fn prefix_dec(&mut self) -> &mut Self { self.offset = self.offset.wrapping_sub(self.elem_step()); - self.clone() + self } } diff --git a/rules/iterator_category/shim.rs b/rules/iterator_category/shim.rs index e4ece4e924..59b078ce6c 100644 --- a/rules/iterator_category/shim.rs +++ b/rules/iterator_category/shim.rs @@ -11,14 +11,14 @@ use crate::{ByteRepr, MapNode, PostfixDec, PostfixInc, PrefixDec, PrefixInc, Ptr pub trait CppIterator: Clone { fn iter_deref(&self) -> Ptr; - fn iter_inc(&mut self) -> Self; + fn iter_inc(&mut self) -> &mut Self; fn iter_post_inc(&mut self) -> Self; } pub trait CppInputIterator: CppIterator + PartialEq {} pub trait CppBidirectionalIterator: CppInputIterator { - fn iter_dec(&mut self) -> Self; + fn iter_dec(&mut self) -> &mut Self; fn iter_post_dec(&mut self) -> Self; } @@ -31,14 +31,14 @@ pub trait CppRandomAccessIterator: CppBidirectionalIterator + PartialOrd { pub trait UnsafeCppIterator: Clone { fn iter_deref(&self) -> *mut T; - fn iter_inc(&mut self) -> Self; + fn iter_inc(&mut self) -> &mut Self; fn iter_post_inc(&mut self) -> Self; } pub trait UnsafeCppInputIterator: UnsafeCppIterator + PartialEq {} pub trait UnsafeCppBidirectionalIterator: UnsafeCppInputIterator { - fn iter_dec(&mut self) -> Self; + fn iter_dec(&mut self) -> &mut Self; fn iter_post_dec(&mut self) -> Self; } @@ -55,7 +55,7 @@ impl CppIterator for Ptr { fn iter_deref(&self) -> Ptr { self.clone() } - fn iter_inc(&mut self) -> Self { + fn iter_inc(&mut self) -> &mut Self { PrefixInc::prefix_inc(self) } fn iter_post_inc(&mut self) -> Self { @@ -66,7 +66,7 @@ impl CppIterator for Ptr { impl CppInputIterator for Ptr {} impl CppBidirectionalIterator for Ptr { - fn iter_dec(&mut self) -> Self { + fn iter_dec(&mut self) -> &mut Self { PrefixDec::prefix_dec(self) } fn iter_post_dec(&mut self) -> Self { @@ -96,9 +96,9 @@ macro_rules! raw_pointer_iterator { fn iter_deref(&self) -> *mut T { $deref(*self) } - fn iter_inc(&mut self) -> Self { + fn iter_inc(&mut self) -> &mut Self { *self = self.wrapping_add(1); - *self + self } fn iter_post_inc(&mut self) -> Self { let old = *self; @@ -110,9 +110,9 @@ macro_rules! raw_pointer_iterator { impl UnsafeCppInputIterator for $ptr {} impl UnsafeCppBidirectionalIterator for $ptr { - fn iter_dec(&mut self) -> Self { + fn iter_dec(&mut self) -> &mut Self { *self = self.wrapping_sub(1); - *self + self } fn iter_post_dec(&mut self) -> Self { let old = *self; @@ -167,6 +167,8 @@ macro_rules! uninhabited_iterator { } } + impl ByteRepr for $name {} + impl PartialEq for $name { fn eq(&self, _: &Self) -> bool { self.never() @@ -181,7 +183,7 @@ macro_rules! uninhabited_iterator_ops { fn iter_deref(&self) -> $ptr { self.never() } - fn iter_inc(&mut self) -> Self { + fn iter_inc(&mut self) -> &mut Self { self.never() } fn iter_post_inc(&mut self) -> Self { @@ -228,6 +230,8 @@ impl Clone for BidirectionalIterator { } } +impl ByteRepr for BidirectionalIterator {} + impl PartialEq for BidirectionalIterator { fn eq(&self, other: &Self) -> bool { match (self, other) { @@ -242,11 +246,11 @@ impl CppIterator for BidirectionalIterator { Self::Map(node) => MapNode::value(node), } } - fn iter_inc(&mut self) -> Self { + fn iter_inc(&mut self) -> &mut Self { match self { Self::Map(node) => *node = MapNode::next(node), } - self.clone() + self } fn iter_post_inc(&mut self) -> Self { let old = self.clone(); @@ -258,11 +262,11 @@ impl CppIterator for BidirectionalIterator { impl CppInputIterator for BidirectionalIterator {} impl CppBidirectionalIterator for BidirectionalIterator { - fn iter_dec(&mut self) -> Self { + fn iter_dec(&mut self) -> &mut Self { match self { Self::Map(node) => *node = MapNode::prev(node), } - self.clone() + self } fn iter_post_dec(&mut self) -> Self { let old = self.clone(); @@ -303,11 +307,11 @@ impl UnsafeCppIterator for UnsafeBidirectionalIterator { Self::Map(node) => UnsafeMapNode::value(*node), } } - fn iter_inc(&mut self) -> Self { + fn iter_inc(&mut self) -> &mut Self { match self { Self::Map(node) => *node = UnsafeMapNode::next(*node), } - self.clone() + self } fn iter_post_inc(&mut self) -> Self { let old = self.clone(); @@ -319,11 +323,11 @@ impl UnsafeCppIterator for UnsafeBidirectionalIterator { impl UnsafeCppInputIterator for UnsafeBidirectionalIterator {} impl UnsafeCppBidirectionalIterator for UnsafeBidirectionalIterator { - fn iter_dec(&mut self) -> Self { + fn iter_dec(&mut self) -> &mut Self { match self { Self::Map(node) => *node = UnsafeMapNode::prev(*node), } - self.clone() + self } fn iter_post_dec(&mut self) -> Self { let old = self.clone(); @@ -352,6 +356,8 @@ macro_rules! random_access_iterator { } } + impl ByteRepr for $name {} + impl PartialEq for $name where $ptr: PartialEq, @@ -380,10 +386,13 @@ macro_rules! random_access_iterator { Self::Vec(p) => $iter::::iter_deref(p), } } - fn iter_inc(&mut self) -> Self { + fn iter_inc(&mut self) -> &mut Self { match self { - Self::Vec(p) => Self::Vec($iter::::iter_inc(p)), + Self::Vec(p) => { + $iter::::iter_inc(p); + } } + self } fn iter_post_inc(&mut self) -> Self { match self { @@ -398,10 +407,13 @@ macro_rules! random_access_iterator { where $ptr: $bidi, { - fn iter_dec(&mut self) -> Self { + fn iter_dec(&mut self) -> &mut Self { match self { - Self::Vec(p) => Self::Vec($bidi::::iter_dec(p)), + Self::Vec(p) => { + $bidi::::iter_dec(p); + } } + self } fn iter_post_dec(&mut self) -> Self { match self { diff --git a/rules/iterator_category/tgt_refcount.rs b/rules/iterator_category/tgt_refcount.rs index 8e3828931d..3fb99eec01 100644 --- a/rules/iterator_category/tgt_refcount.rs +++ b/rules/iterator_category/tgt_refcount.rs @@ -43,8 +43,11 @@ fn f5, T2>(a0: T1) -> Ptr { a0.iter_deref() } -fn f6, T2>(a0: &mut T1) -> T1 { - a0.iter_inc() +fn f6 + ByteRepr, T2>(a0: Ptr) -> Ptr { + a0.with_mut(|__it| { + __it.iter_inc(); + }); + a0 } fn f7, T2>(a0: &mut T1) -> T1 { @@ -63,20 +66,29 @@ fn f10, T2>(a0: T1, a1: T1) -> bool { a0 != a1 } -fn f11, T2>(a0: &mut T1) -> T1 { - a0.iter_dec() +fn f11 + ByteRepr, T2>(a0: Ptr) -> Ptr { + a0.with_mut(|__it| { + __it.iter_dec(); + }); + a0 } fn f12, T2>(a0: &mut T1) -> T1 { a0.iter_post_dec() } -fn f13, T2>(a0: &mut T1, a1: isize) -> T1 { - a0.iter_add_assign(a1) +fn f13 + ByteRepr, T2>(a0: Ptr, a1: isize) -> Ptr { + a0.with_mut(|__it| { + __it.iter_add_assign(a1); + }); + a0 } -fn f14, T2>(a0: &mut T1, a1: isize) -> T1 { - a0.iter_add_assign(-a1) +fn f14 + ByteRepr, T2>(a0: Ptr, a1: isize) -> Ptr { + a0.with_mut(|__it| { + __it.iter_add_assign(-a1); + }); + a0 } fn f15, T2>(a0: T1, a1: isize) -> T1 { @@ -121,12 +133,14 @@ fn f24, T2>(a0: T2) -> T1 { fn f25, T2>(a0: T1) -> T1 { let mut __it = a0; - __it.iter_inc() + __it.iter_inc(); + __it } fn f26, T2>(a0: T1) -> T1 { let mut __it = a0; - __it.iter_dec() + __it.iter_dec(); + __it } fn f27 + PartialEq, T2: CppInputIterator, T3>(a0: T1, a1: T2) -> bool { diff --git a/rules/iterator_category/tgt_unsafe.rs b/rules/iterator_category/tgt_unsafe.rs index e288beda66..0f3698ee0b 100644 --- a/rules/iterator_category/tgt_unsafe.rs +++ b/rules/iterator_category/tgt_unsafe.rs @@ -43,8 +43,9 @@ unsafe fn f5, T2>(a0: T1) -> *mut T2 { a0.iter_deref() } -unsafe fn f6, T2>(a0: &mut T1) -> T1 { - a0.iter_inc() +unsafe fn f6, T2>(a0: *mut T1) -> *mut T1 { + (*a0).iter_inc(); + a0 } unsafe fn f7, T2>(a0: &mut T1) -> T1 { @@ -63,20 +64,23 @@ unsafe fn f10, T2>(a0: T1, a1: T1) -> bool { a0 != a1 } -unsafe fn f11, T2>(a0: &mut T1) -> T1 { - a0.iter_dec() +unsafe fn f11, T2>(a0: *mut T1) -> *mut T1 { + (*a0).iter_dec(); + a0 } unsafe fn f12, T2>(a0: &mut T1) -> T1 { a0.iter_post_dec() } -unsafe fn f13, T2>(a0: &mut T1, a1: isize) -> T1 { - a0.iter_add_assign(a1) +unsafe fn f13, T2>(a0: *mut T1, a1: isize) -> *mut T1 { + (*a0).iter_add_assign(a1); + a0 } -unsafe fn f14, T2>(a0: &mut T1, a1: isize) -> T1 { - a0.iter_add_assign(-a1) +unsafe fn f14, T2>(a0: *mut T1, a1: isize) -> *mut T1 { + (*a0).iter_add_assign(-a1); + a0 } unsafe fn f15, T2>(a0: T1, a1: isize) -> T1 { @@ -121,12 +125,14 @@ unsafe fn f24, T2>(a0: T2) -> T1 { unsafe fn f25, T2>(a0: T1) -> T1 { let mut __it = a0; - __it.iter_inc() + __it.iter_inc(); + __it } unsafe fn f26, T2>(a0: T1) -> T1 { let mut __it = a0; - __it.iter_dec() + __it.iter_dec(); + __it } unsafe fn f27 + PartialEq, T2: UnsafeCppInputIterator, T3>(a0: T1, a1: T2) -> bool { diff --git a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs index 242c22f9c1..1541a53418 100644 --- a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs +++ b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs @@ -135,7 +135,9 @@ impl LifetimeTrackedImpl for Ptr { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } fn use_(&self) { - field!((*self), uses).with_mut(|__v| __v.prefix_inc()); + field!((*self), uses).with_mut(|__v| { + __v.prefix_inc(); + }); (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); } fn copy_assign(&self, _a0: Ptr) -> Ptr { diff --git a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs index 609cf1af21..f6d5af813f 100644 --- a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs +++ b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs @@ -113,7 +113,9 @@ impl LifetimeTrackedImpl for Ptr { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } fn use_(&self) { - field!((*self), uses).with_mut(|__v| __v.prefix_inc()); + field!((*self), uses).with_mut(|__v| { + __v.prefix_inc(); + }); (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); } fn copy_assign(&self, _a0: Ptr) -> Ptr { diff --git a/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs b/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs index 1ec062701b..3e8b2037c3 100644 --- a/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs +++ b/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs @@ -74,13 +74,13 @@ pub struct AssertsDtorCountAtExit { pub expected: i32, } pub fn count_4() -> i32 { - return (*n_6.with(Value::clone).borrow_mut()).prefix_inc(); + return (*(*n_6.with(Value::clone).borrow_mut()).prefix_inc()); } pub fn count_7() -> i32 { - return (*n_9.with(Value::clone).borrow_mut()).prefix_inc(); + return (*(*n_9.with(Value::clone).borrow_mut()).prefix_inc()); } pub fn count_10() -> i32 { - return (*n_12.with(Value::clone).borrow_mut()).prefix_inc(); + return (*(*n_12.with(Value::clone).borrow_mut()).prefix_inc()); } thread_local!( static t_5: Value = Rc::new(RefCell::new(LifetimeTracked::new())); @@ -126,7 +126,7 @@ fn main_0() -> i32 { #[byte_size(1)] pub struct S_14 {} pub fn count_18() -> i32 { - return (*n_20.with(Value::clone).borrow_mut()).prefix_inc(); + return (*(*n_20.with(Value::clone).borrow_mut()).prefix_inc()); } thread_local!( static t_19: Value = Rc::new(RefCell::new(LifetimeTracked::new())); @@ -164,7 +164,9 @@ impl LifetimeTrackedImpl for Ptr { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } fn use_(&self) { - field!((*self), uses).with_mut(|__v| __v.prefix_inc()); + field!((*self), uses).with_mut(|__v| { + __v.prefix_inc(); + }); (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); } fn copy_assign(&self, _a0: Ptr) -> Ptr { diff --git a/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs b/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs index b044d15810..a6782882c0 100644 --- a/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs +++ b/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs @@ -71,13 +71,13 @@ impl AssertsDtorCountAtExit { } } pub unsafe fn count_4() -> i32 { - return (*std::cell::LazyCell::force_mut(&mut *&raw mut n_6)).prefix_inc(); + return (*(*std::cell::LazyCell::force_mut(&mut *&raw mut n_6)).prefix_inc()); } pub unsafe fn count_7() -> i32 { - return (*std::cell::LazyCell::force_mut(&mut *&raw mut n_9)).prefix_inc(); + return (*(*std::cell::LazyCell::force_mut(&mut *&raw mut n_9)).prefix_inc()); } pub unsafe fn count_10() -> i32 { - return (*std::cell::LazyCell::force_mut(&mut *&raw mut n_12)).prefix_inc(); + return (*(*std::cell::LazyCell::force_mut(&mut *&raw mut n_12)).prefix_inc()); } static mut t_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { LifetimeTracked::new() }); @@ -114,7 +114,7 @@ unsafe fn main_0() -> i32 { #[derive(Copy, Clone, VaArg, FnPtrArg, Default)] pub struct S_14 {} pub unsafe fn count_18() -> i32 { - return (*std::cell::LazyCell::force_mut(&mut *&raw mut n_20)).prefix_inc(); + return (*(*std::cell::LazyCell::force_mut(&mut *&raw mut n_20)).prefix_inc()); } static mut t_19: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { LifetimeTracked::new() }); diff --git a/tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs b/tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs index 8ca5bf7f8f..5e0caaa0f5 100644 --- a/tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs +++ b/tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs @@ -123,7 +123,9 @@ impl LifetimeTrackedImpl for Ptr { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } fn use_(&self) { - field!((*self), uses).with_mut(|__v| __v.prefix_inc()); + field!((*self), uses).with_mut(|__v| { + __v.prefix_inc(); + }); (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); } fn copy_assign(&self, _a0: Ptr) -> Ptr { diff --git a/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs b/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs index ea134ef00d..d110a85fe9 100644 --- a/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs +++ b/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs @@ -118,7 +118,9 @@ impl LifetimeTrackedImpl for Ptr { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } fn use_(&self) { - field!((*self), uses).with_mut(|__v| __v.prefix_inc()); + field!((*self), uses).with_mut(|__v| { + __v.prefix_inc(); + }); (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); } fn copy_assign(&self, _a0: Ptr) -> Ptr { diff --git a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs index 2d7b6e2d7f..a7c1b2d88a 100644 --- a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs +++ b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs @@ -120,7 +120,9 @@ impl LifetimeTrackedImpl for Ptr { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } fn use_(&self) { - field!((*self), uses).with_mut(|__v| __v.prefix_inc()); + field!((*self), uses).with_mut(|__v| { + __v.prefix_inc(); + }); (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); } fn copy_assign(&self, _a0: Ptr) -> Ptr { diff --git a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs index 93755e7c79..987dc1fd46 100644 --- a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs +++ b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs @@ -129,7 +129,9 @@ impl LifetimeTrackedImpl for Ptr { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } fn use_(&self) { - field!((*self), uses).with_mut(|__v| __v.prefix_inc()); + field!((*self), uses).with_mut(|__v| { + __v.prefix_inc(); + }); (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); } fn copy_assign(&self, _a0: Ptr) -> Ptr { diff --git a/tests/std/basic/basic.link/out/refcount/basic.link.rs b/tests/std/basic/basic.link/out/refcount/basic.link.rs index 5aeb51e2df..4ab1e76918 100644 --- a/tests/std/basic/basic.link/out/refcount/basic.link.rs +++ b/tests/std/basic/basic.link/out/refcount/basic.link.rs @@ -64,7 +64,7 @@ thread_local!( pub static counter_17: Value = Rc::new(RefCell::new(1)); ); pub fn bump_18() -> i32 { - return (*counter_17.with(Value::clone).borrow_mut()).prefix_inc(); + return (*(*counter_17.with(Value::clone).borrow_mut()).prefix_inc()); } #[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] #[byte_size(4)] @@ -300,7 +300,7 @@ thread_local!( pub static counter_63: Value = Rc::new(RefCell::new(50)); ); pub fn bump_64() -> i32 { - return (*counter_63.with(Value::clone).borrow_mut()).prefix_inc(); + return (*(*counter_63.with(Value::clone).borrow_mut()).prefix_inc()); } #[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] #[byte_size(16)] diff --git a/tests/std/basic/basic.link/out/unsafe/basic.link.rs b/tests/std/basic/basic.link/out/unsafe/basic.link.rs index 46c81ed457..defc6df19d 100644 --- a/tests/std/basic/basic.link/out/unsafe/basic.link.rs +++ b/tests/std/basic/basic.link/out/unsafe/basic.link.rs @@ -57,7 +57,7 @@ pub unsafe fn test_14() { } pub static mut counter_17: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 1 }); pub unsafe fn bump_18() -> i32 { - return (*std::cell::LazyCell::force_mut(&mut *&raw mut counter_17)).prefix_inc(); + return (*(*std::cell::LazyCell::force_mut(&mut *&raw mut counter_17)).prefix_inc()); } #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg)] @@ -263,7 +263,7 @@ pub unsafe fn whole_in_b_16() -> i32 { } pub static mut counter_63: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 50 }); pub unsafe fn bump_64() -> i32 { - return (*std::cell::LazyCell::force_mut(&mut *&raw mut counter_63)).prefix_inc(); + return (*(*std::cell::LazyCell::force_mut(&mut *&raw mut counter_63)).prefix_inc()); } #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg)] diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.block.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.block.rs index 16b392951d..e7bc2ebb0b 100644 --- a/tests/std/basic/basic.scope/out/refcount/basic.scope.block.rs +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.block.rs @@ -297,7 +297,9 @@ impl LifetimeTrackedImpl for Ptr { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } fn use_(&self) { - field!((*self), uses).with_mut(|__v| __v.prefix_inc()); + field!((*self), uses).with_mut(|__v| { + __v.prefix_inc(); + }); (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); } fn copy_assign(&self, _a0: Ptr) -> Ptr { diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.lambda.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.lambda.rs index 9aeffe91b2..28aa9d8946 100644 --- a/tests/std/basic/basic.scope/out/refcount/basic.scope.lambda.rs +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.lambda.rs @@ -13,7 +13,7 @@ pub fn test_0() { let total: Value = Rc::new(RefCell::new((total + 1))); }, || -> i32 { - return (*total.borrow_mut()).prefix_inc(); + return (*(*total.borrow_mut()).prefix_inc()); } ))); assert!((total == 4)); diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.namespace.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.namespace.rs index 4a63c48d8a..200815d82d 100644 --- a/tests/std/basic/basic.scope/out/refcount/basic.scope.namespace.rs +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.namespace.rs @@ -62,7 +62,7 @@ thread_local!( pub static count_14: Value = Rc::new(RefCell::new(100)); ); pub fn next_15() -> i32 { - return (*count_13.with(Value::clone).borrow_mut()).prefix_inc(); + return (*(*count_13.with(Value::clone).borrow_mut()).prefix_inc()); } pub fn test_16() { assert!((({ next_15() }) == 5)); diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.scope.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.scope.rs index 5136bc8628..f48db7c525 100644 --- a/tests/std/basic/basic.scope/out/refcount/basic.scope.scope.rs +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.scope.rs @@ -582,10 +582,10 @@ pub fn test_59() { assert!((revision_57.with(|rc| *rc.borrow()) == 41)); } pub fn next_id_60() -> i32 { - return (*last_61.with(Value::clone).borrow_mut()).prefix_inc(); + return (*(*last_61.with(Value::clone).borrow_mut()).prefix_inc()); } pub fn next_id_62() -> i32 { - return (*last_63.with(Value::clone).borrow_mut()).prefix_inc(); + return (*(*last_63.with(Value::clone).borrow_mut()).prefix_inc()); } pub fn test_64() { assert!((({ next_id_60() }) == 1)); @@ -656,11 +656,15 @@ impl p3_2_const_qualified_member_is_distinct_HasConstOverloadImpl for Ptr { fn get_1(&self) -> i32 { - field!((*self), plain_calls).with_mut(|__v| __v.prefix_inc()); + field!((*self), plain_calls).with_mut(|__v| { + __v.prefix_inc(); + }); return 1; } fn get_2(&self) -> i32 { - field!((*self), const_calls).with_mut(|__v| __v.prefix_inc()); + field!((*self), const_calls).with_mut(|__v| { + __v.prefix_inc(); + }); return 2; } } @@ -710,11 +714,15 @@ impl p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload for Ptr { fn get_1_int(&self, mut value: i32) -> i32 { - field!((*self), plain_calls).with_mut(|__v| __v.prefix_inc()); + field!((*self), plain_calls).with_mut(|__v| { + __v.prefix_inc(); + }); return (value + 1); } fn get_2_int(&self, mut value: i32) -> i32 { - field!((*self), const_calls).with_mut(|__v| __v.prefix_inc()); + field!((*self), const_calls).with_mut(|__v| { + __v.prefix_inc(); + }); return (value + 2); } } diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.lambda.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.lambda.rs index 0cb3a21582..2712a0fc7a 100644 --- a/tests/std/basic/basic.scope/out/unsafe/basic.scope.lambda.rs +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.lambda.rs @@ -13,7 +13,7 @@ pub unsafe fn test_0() { let total: i32 = ((total) + (1)); }, || -> i32 { - return total.prefix_inc(); + return (*total.prefix_inc()); } ); assert!(((total) == (4))); diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.namespace.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.namespace.rs index b1d7024fb3..241f5bafbe 100644 --- a/tests/std/basic/basic.scope/out/unsafe/basic.scope.namespace.rs +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.namespace.rs @@ -53,7 +53,7 @@ pub unsafe fn test_12() { pub static mut count_13: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 4 }); pub static mut count_14: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 100 }); pub unsafe fn next_15() -> i32 { - return (*std::cell::LazyCell::force_mut(&mut *&raw mut count_13)).prefix_inc(); + return (*(*std::cell::LazyCell::force_mut(&mut *&raw mut count_13)).prefix_inc()); } pub unsafe fn test_16() { assert!(((unsafe { next_15() }) == (5))); diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.scope.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.scope.rs index 22a5bb8491..1437c8a9c5 100644 --- a/tests/std/basic/basic.scope/out/unsafe/basic.scope.scope.rs +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.scope.rs @@ -568,10 +568,10 @@ pub unsafe fn test_59() { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut revision_57)) == (41))); } pub unsafe fn next_id_60() -> i32 { - return (*std::cell::LazyCell::force_mut(&mut *&raw mut last_61)).prefix_inc(); + return (*(*std::cell::LazyCell::force_mut(&mut *&raw mut last_61)).prefix_inc()); } pub unsafe fn next_id_62() -> i32 { - return (*std::cell::LazyCell::force_mut(&mut *&raw mut last_63)).prefix_inc(); + return (*(*std::cell::LazyCell::force_mut(&mut *&raw mut last_63)).prefix_inc()); } pub unsafe fn test_64() { assert!(((unsafe { next_id_60() }) == (1))); diff --git a/tests/std/basic/out/refcount/basic.def.odr.rs b/tests/std/basic/out/refcount/basic.def.odr.rs index e8fde44748..7e63d5cc8e 100644 --- a/tests/std/basic/out/refcount/basic.def.odr.rs +++ b/tests/std/basic/out/refcount/basic.def.odr.rs @@ -676,7 +676,9 @@ impl LifetimeTrackedImpl for Ptr { (*dtorCount_3.with(Value::clone).borrow_mut()).prefix_inc(); } fn use_(&self) { - field!((*self), uses).with_mut(|__v| __v.prefix_inc()); + field!((*self), uses).with_mut(|__v| { + __v.prefix_inc(); + }); (*useCount_4.with(Value::clone).borrow_mut()).prefix_inc(); } fn copy_assign(&self, _a0: Ptr) -> Ptr { diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.fct.default.rs b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.fct.default.rs index be048d8eb3..4c38f879d9 100644 --- a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.fct.default.rs +++ b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.fct.default.rs @@ -35,7 +35,7 @@ thread_local!( pub static next_ticket_calls_5: Value = Rc::new(RefCell::new(0_i32)); ); pub fn next_ticket_6() -> i32 { - return ((*next_ticket_calls_5.with(Value::clone).borrow_mut()).prefix_inc() * 100); + return ((*(*next_ticket_calls_5.with(Value::clone).borrow_mut()).prefix_inc()) * 100); } pub fn issue_7(ticket: Option) -> i32 { let mut ticket: i32 = ticket.unwrap_or_else(|| ({ next_ticket_6() })); diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.fct.default.rs b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.fct.default.rs index 52b473d9a9..2638dcbb5c 100644 --- a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.fct.default.rs +++ b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.fct.default.rs @@ -33,7 +33,7 @@ pub unsafe fn test_4() { pub static mut next_ticket_calls_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); pub unsafe fn next_ticket_6() -> i32 { - return (((*std::cell::LazyCell::force_mut(&mut *&raw mut next_ticket_calls_5)).prefix_inc()) + return ((*(*std::cell::LazyCell::force_mut(&mut *&raw mut next_ticket_calls_5)).prefix_inc()) * (100)); } pub unsafe fn issue_7(mut ticket: Option) -> i32 { diff --git a/tests/std/expr/expr.compound/expr.unary/expr.pre.incr.cpp b/tests/std/expr/expr.compound/expr.unary/expr.pre.incr.cpp new file mode 100644 index 0000000000..61fab27133 --- /dev/null +++ b/tests/std/expr/expr.compound/expr.unary/expr.pre.incr.cpp @@ -0,0 +1,70 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +#include + +// N4950 [expr.pre.incr]/1: the operand of prefix ++ is modified by adding 1; +// the result is the updated operand, and it is an lvalue. +namespace p1_result_is_updated_operand { +struct Counter { + int n; +}; + +void test() { + int x = 0; + int &r = ++x; + r = 5; + assert(x == 5); + assert(&r == &x); + (++x) = 7; + assert(x == 7); + int y = ++x; + assert(y == 8 && x == 8); + int &s = r; + (++s) = 1; + assert(x == 1); + int t = ++s; + assert(t == 2 && x == 2); + int a[3] = {1, 2, 3}; + int *p = a; + int *&q = ++p; + assert(&q == &p); + assert(*q == 2); + assert(*++p == 3); + Counter c{0}; + Counter *pc = &c; + int v = ++c.n; + assert(v == 1 && pc->n == 1); + (++c.n) = 4; + assert(pc->n == 4); + int sum = 0; + for (int k = 0; k < 3; ++k) { + sum += ++y; + } + assert(sum == 30 && y == 11); +} +} // namespace p1_result_is_updated_operand + +// N4950 [expr.pre.incr]/2: the operand of prefix -- is modified by subtracting +// 1; the properties of its result are otherwise those of prefix ++. +namespace p2_decrement_result_is_updated_operand { +void test() { + unsigned counter = 0; + unsigned &pre = --counter; + assert(&pre == &counter && counter == ~0u); + int x = 5; + int &r = x; + --r; + assert(x == 4); + (--r) = 9; + assert(x == 9); + int a[3] = {1, 2, 3}; + int *p = a + 2; + int *n = --p; + assert(*n == 2 && n == p); +} +} // namespace p2_decrement_result_is_updated_operand + +int main() { + p1_result_is_updated_operand::test(); + p2_decrement_result_is_updated_operand::test(); + return 0; +} diff --git a/tests/std/expr/expr.compound/expr.unary/out/refcount/expr.pre.incr.rs b/tests/std/expr/expr.compound/expr.unary/out/refcount/expr.pre.incr.rs new file mode 100644 index 0000000000..5856e8a4e9 --- /dev/null +++ b/tests/std/expr/expr.compound/expr.unary/out/refcount/expr.pre.incr.rs @@ -0,0 +1,113 @@ +extern crate libcc2rs; +use libcc2rs::*; +use std::cell::RefCell; +use std::collections::BTreeMap; +use std::io::prelude::*; +use std::io::{Read, Seek, Write}; +use std::os::fd::AsFd; +use std::rc::{Rc, Weak}; +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[byte_size(4)] +pub struct p1_result_is_updated_operand_Counter { + #[offset(0)] + pub n: i32, +} +pub fn test_0() { + let x: Value = Rc::new(RefCell::new(0)); + let r: Ptr = { + let __tmp_0 = x.as_pointer(); + __tmp_0.with_mut(|__v| { + __v.prefix_inc(); + }); + __tmp_0 + }; + r.write(5); + assert!(({ ((*x.borrow()) == 5) })); + assert!(({ (r).clone() } == { (x.as_pointer()) })); + (*(*x.borrow_mut()).prefix_inc()) = 7; + assert!(({ ((*x.borrow()) == 7) })); + let mut y: i32 = (*(*x.borrow_mut()).prefix_inc()); + assert!(({ (y == 8) && ((*x.borrow()) == 8) })); + let s: Ptr = (r).clone(); + { + let __tmp_1 = s.clone(); + __tmp_1.with_mut(|__v| { + __v.prefix_inc(); + }); + __tmp_1 + } + .write(1); + assert!(({ ((*x.borrow()) == 1) })); + let mut t: i32 = s.with_mut(|__v| __v.prefix_inc().clone()); + assert!(({ (t == 2) && ((*x.borrow()) == 2) })); + let a: Value> = Rc::new(RefCell::new(Box::new([1, 2, 3]))); + let p: Value> = Rc::new(RefCell::new(a.decay())); + let q: Ptr> = { + let __tmp_2 = p.as_pointer(); + __tmp_2.with_mut(|__v| { + __v.prefix_inc(); + }); + __tmp_2 + }; + assert!(({ (q).clone() } == { (p.as_pointer()) })); + assert!((((q.read()).read()) == 2)); + assert!(({ (((*(*p.borrow_mut()).prefix_inc()).read()) == 3) })); + let c: Value = + Rc::new(RefCell::new(p1_result_is_updated_operand_Counter { n: 0 })); + let mut pc: Ptr = (c.as_pointer()); + let mut v: i32 = { (*c.borrow_mut()).n.prefix_inc().clone() }; + assert!((v == 1) && (pc.with(|__s| __s.n) == 1)); + (*(*c.borrow_mut()).n.prefix_inc()) = 4; + assert!((pc.with(|__s| __s.n) == 4)); + let mut sum: i32 = 0; + { + let mut k: i32 = 0; + 'loop_: while (k < 3) { + sum += (*y.prefix_inc()); + k.prefix_inc(); + } + } + assert!((sum == 30) && (y == 11)); +} +pub fn test_1() { + let counter: Value = Rc::new(RefCell::new(0_u32)); + let pre: Ptr = { + let __tmp_3 = counter.as_pointer(); + __tmp_3.with_mut(|__v| { + __v.prefix_dec(); + }); + __tmp_3 + }; + assert!( + ({ ({ (pre).clone() } == { (counter.as_pointer()) }) && ((*counter.borrow()) == !0_u32) }) + ); + let x: Value = Rc::new(RefCell::new(5)); + let r: Ptr = x.as_pointer(); + r.with_mut(|__v| { + __v.prefix_dec(); + }); + assert!(({ ((*x.borrow()) == 4) })); + { + let __tmp_4 = r.clone(); + __tmp_4.with_mut(|__v| { + __v.prefix_dec(); + }); + __tmp_4 + } + .write(9); + assert!(({ ((*x.borrow()) == 9) })); + let a: Value> = Rc::new(RefCell::new(Box::new([1, 2, 3]))); + let mut p: Ptr = a.decay().offset((2) as isize); + let mut n: Ptr = (*p.prefix_dec()).clone(); + assert!(((n.read()) == 2) && ({ (n).clone() } == { (p).clone() })); +} +pub fn main() { + __cpp2rust_init_globals(); + std::process::exit(main_0()); +} +fn main_0() -> i32 { + ({ test_0() }); + ({ test_1() }); + return 0; +} +pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/expr/expr.compound/expr.unary/out/unsafe/expr.pre.incr.rs b/tests/std/expr/expr.compound/expr.unary/out/unsafe/expr.pre.incr.rs new file mode 100644 index 0000000000..feb29ff569 --- /dev/null +++ b/tests/std/expr/expr.compound/expr.unary/out/unsafe/expr.pre.incr.rs @@ -0,0 +1,78 @@ +extern crate libc; +use libc::*; +extern crate libcc2rs; +use libcc2rs::*; +use std::collections::BTreeMap; +use std::io::{Read, Seek, Write}; +use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; +use std::rc::Rc; +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct p1_result_is_updated_operand_Counter { + pub n: i32, +} +pub unsafe fn test_0() { + let mut x: i32 = 0; + let r: *mut i32 = &mut (*x.prefix_inc()); + (*r) = 5; + assert!(((x) == (5))); + assert!(((r) == (&mut x as *mut i32))); + (*x.prefix_inc()) = 7; + assert!(((x) == (7))); + let mut y: i32 = (*x.prefix_inc()); + assert!(((y) == (8)) && ((x) == (8))); + let s: *mut i32 = r; + (*(*s).prefix_inc()) = 1; + assert!(((x) == (1))); + let mut t: i32 = (*(*s).prefix_inc()); + assert!(((t) == (2)) && ((x) == (2))); + let mut a: [i32; 3] = [1, 2, 3]; + let mut p: *mut i32 = a.as_mut_ptr(); + let q: *mut *mut i32 = &mut (*p.prefix_inc()); + assert!(((q) == (&mut p as *mut *mut i32))); + assert!(((*(*q)) == (2))); + assert!(((*(*p.prefix_inc())) == (3))); + let mut c: p1_result_is_updated_operand_Counter = p1_result_is_updated_operand_Counter { n: 0 }; + let mut pc: *mut p1_result_is_updated_operand_Counter = + (&mut c as *mut p1_result_is_updated_operand_Counter); + let mut v: i32 = (*c.n.prefix_inc()); + assert!(((v) == (1)) && (((*pc).n) == (1))); + (*c.n.prefix_inc()) = 4; + assert!((((*pc).n) == (4))); + let mut sum: i32 = 0; + { + let mut k: i32 = 0; + 'loop_: while ((k) < (3)) { + sum += (*y.prefix_inc()); + k.prefix_inc(); + } + } + assert!(((sum) == (30)) && ((y) == (11))); +} +pub unsafe fn test_1() { + let mut counter: u32 = 0_u32; + let pre: *mut u32 = &mut (*counter.prefix_dec()); + assert!(((pre) == (&mut counter as *mut u32)) && ((counter) == (!0_u32))); + let mut x: i32 = 5; + let r: *mut i32 = &mut x; + (*r).prefix_dec(); + assert!(((x) == (4))); + (*(*r).prefix_dec()) = 9; + assert!(((x) == (9))); + let mut a: [i32; 3] = [1, 2, 3]; + let mut p: *mut i32 = a.as_mut_ptr().offset((2) as isize); + let mut n: *mut i32 = (*p.prefix_dec()); + assert!(((*n) == (2)) && ((n) == (p))); +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + std::process::exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + (unsafe { test_0() }); + (unsafe { test_1() }); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/std/expr/expr.compound/out/refcount/expr.ass.rs b/tests/std/expr/expr.compound/out/refcount/expr.ass.rs index 265367bd01..4363c5d662 100644 --- a/tests/std/expr/expr.compound/out/refcount/expr.ass.rs +++ b/tests/std/expr/expr.compound/out/refcount/expr.ass.rs @@ -7,7 +7,9 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; pub fn next_0(mut pp: Ptr>, calls: Ptr) -> Ptr> { - calls.with_mut(|__v| __v.prefix_inc()); + calls.with_mut(|__v| { + __v.prefix_inc(); + }); return (pp).clone(); } pub fn test_1() { diff --git a/tests/std/expr/expr.compound/out/refcount/expr.mptr.oper.rs b/tests/std/expr/expr.compound/out/refcount/expr.mptr.oper.rs index 3af893a4bd..3c7145480d 100644 --- a/tests/std/expr/expr.compound/out/refcount/expr.mptr.oper.rs +++ b/tests/std/expr/expr.compound/out/refcount/expr.mptr.oper.rs @@ -48,13 +48,15 @@ thread_local!( ); ); pub fn select_object_5() -> Ptr { - object_stamp_2 - .with(|rc| *rc.borrow_mut() = (*sequence_1.with(Value::clone).borrow_mut()).prefix_inc()); + object_stamp_2.with(|rc| { + *rc.borrow_mut() = (*(*sequence_1.with(Value::clone).borrow_mut()).prefix_inc()) + }); return object_4.with(|v| v.as_pointer()); } pub fn select_member_6() -> isize { - member_stamp_3 - .with(|rc| *rc.borrow_mut() = (*sequence_1.with(Value::clone).borrow_mut()).prefix_inc()); + member_stamp_3.with(|rc| { + *rc.borrow_mut() = (*(*sequence_1.with(Value::clone).borrow_mut()).prefix_inc()) + }); return (offset_of_field!(p4_object_expression_sequenced_first_HasValue, value) as isize); } pub fn test_7() { diff --git a/tests/std/expr/expr.compound/out/unsafe/expr.mptr.oper.rs b/tests/std/expr/expr.compound/out/unsafe/expr.mptr.oper.rs index b77b402a30..14c22d0921 100644 --- a/tests/std/expr/expr.compound/out/unsafe/expr.mptr.oper.rs +++ b/tests/std/expr/expr.compound/out/unsafe/expr.mptr.oper.rs @@ -46,12 +46,12 @@ pub static mut object_4: std::cell::LazyCell *mut p4_object_expression_sequenced_first_HasValue { (*std::cell::LazyCell::force_mut(&mut *&raw mut object_stamp_2)) = - (*std::cell::LazyCell::force_mut(&mut *&raw mut sequence_1)).prefix_inc(); + (*(*std::cell::LazyCell::force_mut(&mut *&raw mut sequence_1)).prefix_inc()); return &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut object_4)); } pub unsafe fn select_member_6() -> isize { (*std::cell::LazyCell::force_mut(&mut *&raw mut member_stamp_3)) = - (*std::cell::LazyCell::force_mut(&mut *&raw mut sequence_1)).prefix_inc(); + (*(*std::cell::LazyCell::force_mut(&mut *&raw mut sequence_1)).prefix_inc()); return (::std::mem::offset_of!(p4_object_expression_sequenced_first_HasValue, value) as isize); } pub unsafe fn test_7() { diff --git a/tests/std/expr/expr.prim/expr.prim.lambda/out/refcount/expr.prim.lambda.capture.rs b/tests/std/expr/expr.prim/expr.prim.lambda/out/refcount/expr.prim.lambda.capture.rs index 2bd8372e55..d98667ce29 100644 --- a/tests/std/expr/expr.prim/expr.prim.lambda/out/refcount/expr.prim.lambda.capture.rs +++ b/tests/std/expr/expr.prim/expr.prim.lambda/out/refcount/expr.prim.lambda.capture.rs @@ -15,7 +15,9 @@ pub fn test_0() { let n: Ptr = n.as_pointer(); }, || { - n.with_mut(|__v| __v.prefix_inc()); + n.with_mut(|__v| { + __v.prefix_inc(); + }); } ))); ({ (*increment.borrow()).call() }); diff --git a/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.if.rs b/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.if.rs index f13255dab2..75f94bcfa9 100644 --- a/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.if.rs +++ b/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.if.rs @@ -130,7 +130,9 @@ impl LifetimeTrackedImpl for Ptr { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } fn use_(&self) { - field!((*self), uses).with_mut(|__v| __v.prefix_inc()); + field!((*self), uses).with_mut(|__v| { + __v.prefix_inc(); + }); (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); } fn copy_assign(&self, _a0: Ptr) -> Ptr { diff --git a/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.switch.rs b/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.switch.rs index a97555cd84..166e5ac592 100644 --- a/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.switch.rs +++ b/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.switch.rs @@ -172,7 +172,9 @@ impl LifetimeTrackedImpl for Ptr { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } fn use_(&self) { - field!((*self), uses).with_mut(|__v| __v.prefix_inc()); + field!((*self), uses).with_mut(|__v| { + __v.prefix_inc(); + }); (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); } fn copy_assign(&self, _a0: Ptr) -> Ptr { diff --git a/tests/ub/out/refcount/ub8.rs b/tests/ub/out/refcount/ub8.rs index c01bccd130..6e20f5c00d 100644 --- a/tests/ub/out/refcount/ub8.rs +++ b/tests/ub/out/refcount/ub8.rs @@ -13,6 +13,6 @@ pub fn main() { fn main_0() -> i32 { let x: Value = Rc::new(RefCell::new(5)); let mut p: Ptr = (x.as_pointer()); - return (p.prefix_inc().read()); + return ((*p.prefix_inc()).read()); } pub fn __cpp2rust_init_globals() {} diff --git a/tests/ub/out/unsafe/ub8.rs b/tests/ub/out/unsafe/ub8.rs index 7c533cda17..4242a15f59 100644 --- a/tests/ub/out/unsafe/ub8.rs +++ b/tests/ub/out/unsafe/ub8.rs @@ -15,6 +15,6 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut x: i32 = 5; let mut p: *mut i32 = (&mut x as *mut i32); - return (*p.prefix_inc()); + return (*(*p.prefix_inc())); } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/map.cpp b/tests/unit/map.cpp index caa288ecd8..61b5f0631e 100644 --- a/tests/unit/map.cpp +++ b/tests/unit/map.cpp @@ -144,6 +144,11 @@ int main() { assert(points[8].x == 5); assert(points[8].y == 6); assert(points.size() == 2); + auto mi = m3.begin(); + auto &mr = ++mi; + assert(&mr == &mi && mi->first == 4); + auto &md = --mi; + assert(&md == &mi && mi->first == 1); k = 0; const auto &value_0 = m.at(k); assert(m.size() + x1 + x2 + x3 + x4 + x5 + value_0 == 21); diff --git a/tests/unit/out/refcount/alloc_array.rs b/tests/unit/out/refcount/alloc_array.rs index 3d995d3501..cdee991c59 100644 --- a/tests/unit/out/refcount/alloc_array.rs +++ b/tests/unit/out/refcount/alloc_array.rs @@ -22,7 +22,7 @@ pub fn All_0(arr: Ptr>>>, mut N: i32, mut element: i32) pub fn Consume_1(mut arr: Option>>, mut N: i32) -> i32 { let mut sum: i32 = 0; let mut i: i32 = -1_i32; - 'loop_: while (i.prefix_inc() < N) { + 'loop_: while ((*i.prefix_inc()) < N) { sum += (arr.decay().offset((i as usize)).read()); } return sum; diff --git a/tests/unit/out/refcount/assign_rhs_first.rs b/tests/unit/out/refcount/assign_rhs_first.rs index 87d18a26de..c5b5c21061 100644 --- a/tests/unit/out/refcount/assign_rhs_first.rs +++ b/tests/unit/out/refcount/assign_rhs_first.rs @@ -10,7 +10,9 @@ thread_local!( pub static g_cursor_0: Value>> = Rc::new(RefCell::new(Ptr::>::null())); ); pub fn advance_1() -> i32 { - (*g_cursor_0.with(Value::clone).borrow()).with_mut(|__v| __v.prefix_inc()); + (*g_cursor_0.with(Value::clone).borrow()).with_mut(|__v| { + __v.prefix_inc(); + }); return 10; } #[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] diff --git a/tests/unit/out/refcount/class.rs b/tests/unit/out/refcount/class.rs index 3024b5c0ef..3dbc778980 100644 --- a/tests/unit/out/refcount/class.rs +++ b/tests/unit/out/refcount/class.rs @@ -113,11 +113,15 @@ pub trait CounterImpl { } impl CounterImpl for Ptr { fn Get(&self) -> i32 { - field!((*self), calls).with_mut(|__v| __v.prefix_inc()); + field!((*self), calls).with_mut(|__v| { + __v.prefix_inc(); + }); return (*self).with(|__s| __s.v); } fn operator_eq(&self, o: Ptr) -> bool { - field!((*self), calls).with_mut(|__v| __v.prefix_inc()); + field!((*self), calls).with_mut(|__v| { + __v.prefix_inc(); + }); return ({ (*self).with(|__s| __s.v) } == { o.with(|__s| __s.v) }); } } diff --git a/tests/unit/out/refcount/clone_vs_move.rs b/tests/unit/out/refcount/clone_vs_move.rs index a7f91f176a..b1dfd8b051 100644 --- a/tests/unit/out/refcount/clone_vs_move.rs +++ b/tests/unit/out/refcount/clone_vs_move.rs @@ -80,7 +80,9 @@ fn main_0() -> i32 { assert!((x6 == 2)); let mut other_pointer: Ptr = (pointer).clone(); assert!(({ (other_pointer).clone() } == { (pointer).clone() })); - other_pointer.with_mut(|__v| __v.prefix_inc()); + other_pointer.with_mut(|__v| { + __v.prefix_inc(); + }); assert!(({ (other_pointer.read()) } == { (pointer.read()) })); let mut f1: Foo = Foo { x: 1, @@ -95,12 +97,16 @@ fn main_0() -> i32 { assert!(((f1.z.read()) == 2)); let mut f2: Foo = (f1).clone(); f2.x.prefix_inc(); - f2.y.with_mut(|__v| __v.prefix_inc()); + f2.y.with_mut(|__v| { + __v.prefix_inc(); + }); assert!((f2.x == 2)); assert!(((f2.y.read()) == 3)); assert!((f1.x == 1)); assert!(((f1.y.read()) == 3)); - f2.z.with_mut(|__v| __v.prefix_inc()); + f2.z.with_mut(|__v| { + __v.prefix_inc(); + }); assert!(((f2.y.read()) == 4)); assert!(({ (f2.z).clone() } == { (x1.as_pointer()) })); assert!(((f2.z.read()) == 4)); @@ -229,7 +235,9 @@ fn main_0() -> i32 { assert!( ({ ((Map::subscript(map2.as_pointer(), i.as_pointer()).read()) == (*i.borrow())) }) ); - Map::subscript(map2.as_pointer(), i.as_pointer()).with_mut(|__v| __v.prefix_inc()); + Map::subscript(map2.as_pointer(), i.as_pointer()).with_mut(|__v| { + __v.prefix_inc(); + }); (*i.borrow_mut()).prefix_inc(); } } @@ -328,7 +336,9 @@ fn main_0() -> i32 { }; let mut r2: Refs = (r1).clone(); r2.a.write(10); - r2.b.with_mut(|__v| __v.prefix_inc()); + r2.b.with_mut(|__v| { + __v.prefix_inc(); + }); assert!(({ ((*ra.borrow()) == 10) })); assert!(({ ((*rb.borrow()) == 3) })); assert!(((r1.a.read()) == 10)); diff --git a/tests/unit/out/refcount/complex_function.rs b/tests/unit/out/refcount/complex_function.rs index 002759a467..29ee87e090 100644 --- a/tests/unit/out/refcount/complex_function.rs +++ b/tests/unit/out/refcount/complex_function.rs @@ -111,7 +111,7 @@ fn main_0() -> i32 { )) }) .read()); - let mut bar_inc: i32 = ({ bar_2(x1.as_pointer()) }).with_mut(|__v| __v.prefix_inc()); + let mut bar_inc: i32 = ({ bar_2(x1.as_pointer()) }).with_mut(|__v| __v.prefix_inc().clone()); bar_inc = ({ bar_2(x1.as_pointer()) }).with_mut(|__v| __v.postfix_inc()); bar_inc = (((({ bar_2(x1.as_pointer()) }).read()) + ({ foo_0(x4) })) + 1); { @@ -136,7 +136,7 @@ fn main_0() -> i32 { v )) }) - .with_mut(|__v| __v.prefix_inc()); + .with_mut(|__v| __v.prefix_inc().clone()); bar_inc2 = ({ bar_2(field_ptr!( ({ X2Impl::get(&({ X3Impl::get(&({ X4Impl::get(&d.as_pointer(),) }),) }),) }), @@ -144,7 +144,9 @@ fn main_0() -> i32 { )) }) .with_mut(|__v| __v.postfix_inc()); - ({ ptr_1((x1.as_pointer())) }).with_mut(|__v| __v.prefix_inc()); + ({ ptr_1((x1.as_pointer())) }).with_mut(|__v| { + __v.prefix_inc(); + }); { ({ ptr_1((x1.as_pointer())) }).with_mut(|__v| *__v = *__v + 1) }; @@ -156,7 +158,9 @@ fn main_0() -> i32 { )), ) }) - .with_mut(|__v| __v.prefix_inc()); + .with_mut(|__v| { + __v.prefix_inc(); + }); { ({ ptr_1( diff --git a/tests/unit/out/refcount/container_element_receiver.rs b/tests/unit/out/refcount/container_element_receiver.rs index 02d2129701..b1aad6565e 100644 --- a/tests/unit/out/refcount/container_element_receiver.rs +++ b/tests/unit/out/refcount/container_element_receiver.rs @@ -33,7 +33,12 @@ pub fn sum_1(v: Ptr>) -> i32 { let it: Value> = Rc::new(RefCell::new(v.decay().begin())); 'loop_: while (*it.borrow()) != v.decay().end() { total += ((*it.borrow()).iter_deref().read()); - (*it.borrow_mut()).iter_inc(); + { + it.as_pointer().with_mut(|__it| { + __it.iter_inc(); + }); + it.as_pointer() + }; } } return ({ total } + { diff --git a/tests/unit/out/refcount/copy_ctor.rs b/tests/unit/out/refcount/copy_ctor.rs index be13b9132a..307da3228d 100644 --- a/tests/unit/out/refcount/copy_ctor.rs +++ b/tests/unit/out/refcount/copy_ctor.rs @@ -192,7 +192,9 @@ pub struct Tracked { impl Tracked { pub fn copy_from(o: Ptr) -> Self { let __this: Tracked = Self { copied_from: 0 }; - field!(o, copied_from).with_mut(|__v| __v.prefix_inc()); + field!(o, copied_from).with_mut(|__v| { + __v.prefix_inc(); + }); __this } } @@ -210,7 +212,9 @@ impl Default for Tracked { } } pub fn touch_1(mut t: Ptr) { - field!(t, copied_from).with_mut(|__v| __v.prefix_inc()); + field!(t, copied_from).with_mut(|__v| { + __v.prefix_inc(); + }); } pub fn by_value_2(mut c: Counted) -> i32 { return c.v; @@ -346,7 +350,9 @@ pub trait TrackedImpl { } impl TrackedImpl for Ptr { fn copy_assign(&self, o: Ptr) -> Ptr { - field!(o, copied_from).with_mut(|__v| __v.prefix_inc()); + field!(o, copied_from).with_mut(|__v| { + __v.prefix_inc(); + }); return (*self).clone(); } } diff --git a/tests/unit/out/refcount/default_function_arguments.rs b/tests/unit/out/refcount/default_function_arguments.rs index cbc409f1f6..eeced5778f 100644 --- a/tests/unit/out/refcount/default_function_arguments.rs +++ b/tests/unit/out/refcount/default_function_arguments.rs @@ -36,7 +36,7 @@ thread_local!( pub static counter_2: Value = Rc::new(RefCell::new(0)); ); pub fn next_3() -> i32 { - return (*counter_2.with(Value::clone).borrow_mut()).prefix_inc(); + return (*(*counter_2.with(Value::clone).borrow_mut()).prefix_inc()); } pub fn lazy_4(x: Option) -> i32 { let mut x: i32 = x.unwrap_or_else(|| ({ next_3() })); diff --git a/tests/unit/out/refcount/enum_increment.rs b/tests/unit/out/refcount/enum_increment.rs index 620725acbb..db2d46e755 100644 --- a/tests/unit/out/refcount/enum_increment.rs +++ b/tests/unit/out/refcount/enum_increment.rs @@ -27,9 +27,9 @@ fn main_0() -> i32 { assert!((count == 3)); let mut c: color = color_RED; assert!(((c.postfix_inc() as u32) == ((color_RED as i32) as u32))); - assert!(((c.prefix_inc() as u32) == ((color_BLUE as i32) as u32))); + assert!((((*c.prefix_inc()) as u32) == ((color_BLUE as i32) as u32))); assert!(((c.postfix_dec() as u32) == ((color_BLUE as i32) as u32))); - assert!(((c.prefix_dec() as u32) == ((color_RED as i32) as u32))); + assert!((((*c.prefix_dec()) as u32) == ((color_RED as i32) as u32))); return 0; } pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/foreach_mut.rs b/tests/unit/out/refcount/foreach_mut.rs index fb903801f4..095da2111f 100644 --- a/tests/unit/out/refcount/foreach_mut.rs +++ b/tests/unit/out/refcount/foreach_mut.rs @@ -27,7 +27,7 @@ fn main_0() -> i32 { let mut sum: i32 = 0; 'loop_: for x in IterRange::new(v1.decay().begin(), v1.decay().end()) { let mut x: i32 = (x.iter_deref().read()); - sum += x.prefix_inc(); + sum += (*x.prefix_inc()); } 'loop_: for x in IterRange::new(v1.decay().begin(), v1.decay().end()) { let mut x: i32 = (x.iter_deref().read()); diff --git a/tests/unit/out/refcount/global_non_const_init.rs b/tests/unit/out/refcount/global_non_const_init.rs index 7aa0350ce6..c9bea005b1 100644 --- a/tests/unit/out/refcount/global_non_const_init.rs +++ b/tests/unit/out/refcount/global_non_const_init.rs @@ -7,7 +7,7 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; pub fn next_0() -> i32 { - return (*counter_1.with(Value::clone).borrow_mut()).prefix_inc(); + return (*(*counter_1.with(Value::clone).borrow_mut()).prefix_inc()); } thread_local!( static counter_1: Value = Rc::new(RefCell::new(0)); diff --git a/tests/unit/out/refcount/huffman.rs b/tests/unit/out/refcount/huffman.rs index 8081a7dedf..34c830814d 100644 --- a/tests/unit/out/refcount/huffman.rs +++ b/tests/unit/out/refcount/huffman.rs @@ -154,7 +154,9 @@ pub fn CollectCode_3( i.prefix_inc(); } } - next.with_mut(|__v| __v.prefix_inc()); + next.with_mut(|__v| { + __v.prefix_inc(); + }); } pub fn CollectCodes_4( mut root: Ptr, @@ -364,7 +366,9 @@ impl MinHeapImpl for Ptr { .decay() .offset(0_usize) .read()); - field!((*self), size).with_mut(|__v| __v.prefix_dec()); + field!((*self), size).with_mut(|__v| { + __v.prefix_dec(); + }); let __rhs = ((*self) .with(|__s| __s.arr.clone()) .decay() @@ -379,7 +383,9 @@ impl MinHeapImpl for Ptr { return out; } fn Insert(&self, mut node: Ptr) { - field!((*self), size).with_mut(|__v| __v.prefix_inc()); + field!((*self), size).with_mut(|__v| { + __v.prefix_inc(); + }); let mut i: i32 = ((*self).with(|__s| __s.size) - 1); 'loop_: while (i != 0) && ({ node.with(|__s| __s.freq) } < { diff --git a/tests/unit/out/refcount/iterators.rs b/tests/unit/out/refcount/iterators.rs index c74aa414a2..d1c9e375ad 100644 --- a/tests/unit/out/refcount/iterators.rs +++ b/tests/unit/out/refcount/iterators.rs @@ -21,7 +21,9 @@ fn main_0() -> i32 { RandomAccessIterator::Vec(x.decay().to_last()), ) { let c: Ptr = c.iter_deref(); - c.with_mut(|__v| __v.prefix_inc()); + c.with_mut(|__v| { + __v.prefix_inc(); + }); } 'loop_: for c in IterRange::new( RandomAccessIterator::Vec(x.decay()), diff --git a/tests/unit/out/refcount/lambda_capture_library_types.rs b/tests/unit/out/refcount/lambda_capture_library_types.rs index 2b2f0e781f..ef3afa4154 100644 --- a/tests/unit/out/refcount/lambda_capture_library_types.rs +++ b/tests/unit/out/refcount/lambda_capture_library_types.rs @@ -47,7 +47,7 @@ fn main_0() -> i32 { let n: Value = Rc::new(RefCell::new((*n.borrow()))); }, || -> i32 { - return (*n.borrow_mut()).prefix_inc(); + return (*(*n.borrow_mut()).prefix_inc()); } ))); let outer: Value i32>> = Rc::new(RefCell::new(lambda!( diff --git a/tests/unit/out/refcount/lambda_static_local.rs b/tests/unit/out/refcount/lambda_static_local.rs index 7ca3633c7b..2f4ffd47bf 100644 --- a/tests/unit/out/refcount/lambda_static_local.rs +++ b/tests/unit/out/refcount/lambda_static_local.rs @@ -17,7 +17,7 @@ fn main_0() -> i32 { let next: Value i32>> = Rc::new(RefCell::new(FnPtr:: i32>::new(|| -> i32 { { - return (*n_1.with(Value::clone).borrow_mut()).prefix_inc(); + return (*(*n_1.with(Value::clone).borrow_mut()).prefix_inc()); } }))); assert!(({ (({ (*next.borrow()).call() }) == 1) })); @@ -28,7 +28,7 @@ fn main_0() -> i32 { let fresh: Value i32>> = Rc::new(RefCell::new(FnPtr:: i32>::new(|| -> i32 { { - return (*n_1.with(Value::clone).borrow_mut()).prefix_inc(); + return (*(*n_1.with(Value::clone).borrow_mut()).prefix_inc()); } }))); assert!(({ (({ (*fresh.borrow()).call() }) == 5) })); diff --git a/tests/unit/out/refcount/map.rs b/tests/unit/out/refcount/map.rs index c4ed1ab17e..bcc43c6cbc 100644 --- a/tests/unit/out/refcount/map.rs +++ b/tests/unit/out/refcount/map.rs @@ -272,7 +272,9 @@ fn main_0() -> i32 { assert!(({ ((*(*(*it4.borrow()).iter_deref().upgrade().deref()).1.borrow()) == 5_u32) })); assert!(((p.read()) == 5_u32)); assert!((x5 == 5_u32)); - p.with_mut(|__v| __v.prefix_inc()); + p.with_mut(|__v| { + __v.prefix_inc(); + }); assert!( ((Map::subscript_move( m.as_pointer(), @@ -737,6 +739,34 @@ fn main_0() -> i32 { == 6) ); assert!(({ ((*points.borrow()).len() == 2_usize) })); + let mi: Value, Value)>> = Rc::new(RefCell::new( + m3.as_pointer() + .with(|__m: &Map, Value)>| __m.begin()), + )); + let mr: Ptr, Value)>> = { + mi.as_pointer().with_mut(|__it| { + __it.iter_inc(); + }); + mi.as_pointer() + }; + assert!( + ({ + ({ (mr).clone() } == { (mi.as_pointer()) }) + && ((*(*(*mi.borrow()).iter_deref().upgrade().deref()).0.borrow()) == 4) + }) + ); + let md: Ptr, Value)>> = { + mi.as_pointer().with_mut(|__it| { + __it.iter_dec(); + }); + mi.as_pointer() + }; + assert!( + ({ + ({ (md).clone() } == { (mi.as_pointer()) }) + && ((*(*(*mi.borrow()).iter_deref().upgrade().deref()).0.borrow()) == 1) + }) + ); k = 0; let value_0: Ptr = ({ let __tmp_15: Value = Rc::new(RefCell::new((k as i16))); diff --git a/tests/unit/out/refcount/map_try_emplace.rs b/tests/unit/out/refcount/map_try_emplace.rs index b52f42561b..b82aa790f5 100644 --- a/tests/unit/out/refcount/map_try_emplace.rs +++ b/tests/unit/out/refcount/map_try_emplace.rs @@ -127,7 +127,9 @@ thread_local!( )> = Rc::new(RefCell::new( match ({ let __tmp_1 = global_counter_8.with(|v| v.as_pointer()); - __tmp_1.with_mut(|__v| __v.prefix_inc()); + __tmp_1.with_mut(|__v| { + __v.prefix_inc(); + }); __tmp_1 },) { @@ -230,7 +232,9 @@ fn main_0() -> i32 { } else { match ({ let __tmp_5 = counter.as_pointer(); - __tmp_5.with_mut(|__v| __v.prefix_inc()); + __tmp_5.with_mut(|__v| { + __v.prefix_inc(); + }); __tmp_5 },) { diff --git a/tests/unit/out/refcount/map_try_emplace_lvalues.rs b/tests/unit/out/refcount/map_try_emplace_lvalues.rs index 86c36faed8..c85d6640a1 100644 --- a/tests/unit/out/refcount/map_try_emplace_lvalues.rs +++ b/tests/unit/out/refcount/map_try_emplace_lvalues.rs @@ -214,13 +214,17 @@ thread_local!( match (if global_choose_13.with(|rc| *rc.borrow()) { { let __tmp_4 = global_a_11.with(|v| v.as_pointer()); - __tmp_4.with_mut(|__v| __v.prefix_inc()); + __tmp_4.with_mut(|__v| { + __v.prefix_inc(); + }); __tmp_4 } } else { { let __tmp_5 = global_b_12.with(|v| v.as_pointer()); - __tmp_5.with_mut(|__v| __v.prefix_inc()); + __tmp_5.with_mut(|__v| { + __v.prefix_inc(); + }); __tmp_5 } },) @@ -353,7 +357,9 @@ fn main_0() -> i32 { )> = Rc::new(RefCell::new( match (({ receiver_2(m.as_pointer()) }), { let __tmp_10 = ({ place_3(counter.as_pointer()) }); - __tmp_10.with_mut(|__v| __v.prefix_inc()); + __tmp_10.with_mut(|__v| { + __v.prefix_inc(); + }); __tmp_10 }) { (__tmp_8, __tmp_9) => { @@ -384,7 +390,9 @@ fn main_0() -> i32 { )> = Rc::new(RefCell::new( match ({ let __tmp_12 = counter.as_pointer(); - __tmp_12.with_mut(|__v| __v.prefix_inc()); + __tmp_12.with_mut(|__v| { + __v.prefix_inc(); + }); __tmp_12 },) { @@ -488,7 +496,9 @@ fn main_0() -> i32 { (*key.borrow_mut()).prefix_inc(); match ({ let __tmp_20 = array.decay().offset(index.postfix_inc()); - __tmp_20.with_mut(|__v| __v.prefix_inc()); + __tmp_20.with_mut(|__v| { + __v.prefix_inc(); + }); __tmp_20 },) { @@ -566,13 +576,17 @@ fn main_0() -> i32 { match (if choose { { let __tmp_28 = a.as_pointer(); - __tmp_28.with_mut(|__v| __v.prefix_inc()); + __tmp_28.with_mut(|__v| { + __v.prefix_inc(); + }); __tmp_28 } } else { { let __tmp_29 = b.as_pointer(); - __tmp_29.with_mut(|__v| __v.prefix_inc()); + __tmp_29.with_mut(|__v| { + __v.prefix_inc(); + }); __tmp_29 } },) @@ -599,13 +613,17 @@ fn main_0() -> i32 { match (if choose { { let __tmp_31 = a.as_pointer(); - __tmp_31.with_mut(|__v| __v.prefix_inc()); + __tmp_31.with_mut(|__v| { + __v.prefix_inc(); + }); __tmp_31 } } else { { let __tmp_32 = b.as_pointer(); - __tmp_32.with_mut(|__v| __v.prefix_inc()); + __tmp_32.with_mut(|__v| { + __v.prefix_inc(); + }); __tmp_32 } },) @@ -741,7 +759,9 @@ fn main_0() -> i32 { Map::erase_key(changed.as_pointer(), &key.as_pointer()); { let __tmp_41 = effects.as_pointer(); - __tmp_41.with_mut(|__v| __v.prefix_inc()); + __tmp_41.with_mut(|__v| { + __v.prefix_inc(); + }); __tmp_41 } },) @@ -778,10 +798,14 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match ({ - Map::subscript(changed.as_pointer(), key.as_pointer()).with_mut(|__v| __v.prefix_inc()); + Map::subscript(changed.as_pointer(), key.as_pointer()).with_mut(|__v| { + __v.prefix_inc(); + }); { let __tmp_43 = effects.as_pointer(); - __tmp_43.with_mut(|__v| __v.prefix_inc()); + __tmp_43.with_mut(|__v| { + __v.prefix_inc(); + }); __tmp_43 } },) @@ -881,7 +905,9 @@ fn main_0() -> i32 { )> = Rc::new(RefCell::new( match ({ let __tmp_48 = moved.as_pointer(); - __tmp_48.with_mut(|__v| __v.prefix_inc()); + __tmp_48.with_mut(|__v| { + __v.prefix_inc(); + }); __tmp_48 },) { @@ -906,7 +932,9 @@ fn main_0() -> i32 { )> = Rc::new(RefCell::new( match ({ let __tmp_50 = forwarded.as_pointer(); - __tmp_50.with_mut(|__v| __v.prefix_inc()); + __tmp_50.with_mut(|__v| { + __v.prefix_inc(); + }); __tmp_50 },) { @@ -931,7 +959,9 @@ fn main_0() -> i32 { )> = Rc::new(RefCell::new( match ({ let __tmp_52 = xvalue.as_pointer(); - __tmp_52.with_mut(|__v| __v.prefix_inc()); + __tmp_52.with_mut(|__v| { + __v.prefix_inc(); + }); __tmp_52 },) { @@ -956,7 +986,9 @@ fn main_0() -> i32 { )> = Rc::new(RefCell::new( match ({ let __tmp_54 = lvalue.as_pointer(); - __tmp_54.with_mut(|__v| __v.prefix_inc()); + __tmp_54.with_mut(|__v| { + __v.prefix_inc(); + }); __tmp_54 },) { @@ -1094,13 +1126,17 @@ fn main_0() -> i32 { match (if (choose != 0) { { let __tmp_62 = a.as_pointer(); - __tmp_62.with_mut(|__v| __v.prefix_inc()); + __tmp_62.with_mut(|__v| { + __v.prefix_inc(); + }); __tmp_62 } } else { { let __tmp_63 = b.as_pointer(); - __tmp_63.with_mut(|__v| __v.prefix_inc()); + __tmp_63.with_mut(|__v| { + __v.prefix_inc(); + }); __tmp_63 } },) diff --git a/tests/unit/out/refcount/operator_arithmetic_free.rs b/tests/unit/out/refcount/operator_arithmetic_free.rs index 77f59ee07f..c750c481f2 100644 --- a/tests/unit/out/refcount/operator_arithmetic_free.rs +++ b/tests/unit/out/refcount/operator_arithmetic_free.rs @@ -48,21 +48,29 @@ pub fn operator_neg_6(a: Ptr) -> S { }; } pub fn operator_inc_7(a: Ptr) -> Ptr { - field!(a, v).with_mut(|__v| __v.prefix_inc()); + field!(a, v).with_mut(|__v| { + __v.prefix_inc(); + }); return (a).clone(); } pub fn operator_post_inc_8(a: Ptr, mut _a1: i32) -> S { let mut old: S = (*a.upgrade().deref()).clone(); - field!(a, v).with_mut(|__v| __v.prefix_inc()); + field!(a, v).with_mut(|__v| { + __v.prefix_inc(); + }); return old; } pub fn operator_dec_9(a: Ptr) -> Ptr { - field!(a, v).with_mut(|__v| __v.prefix_dec()); + field!(a, v).with_mut(|__v| { + __v.prefix_dec(); + }); return (a).clone(); } pub fn operator_post_dec_10(a: Ptr, mut _a1: i32) -> S { let mut old: S = (*a.upgrade().deref()).clone(); - field!(a, v).with_mut(|__v| __v.prefix_dec()); + field!(a, v).with_mut(|__v| { + __v.prefix_dec(); + }); return old; } pub fn operator_add_11(a: Ptr, mut b: i32) -> S { diff --git a/tests/unit/out/refcount/operator_arithmetic_member.rs b/tests/unit/out/refcount/operator_arithmetic_member.rs index 5ad3e6ab38..b288aab249 100644 --- a/tests/unit/out/refcount/operator_arithmetic_member.rs +++ b/tests/unit/out/refcount/operator_arithmetic_member.rs @@ -101,21 +101,29 @@ impl SImpl for Ptr { }; } fn operator_inc_8(&self) -> Ptr { - field!((*self), v).with_mut(|__v| __v.prefix_inc()); + field!((*self), v).with_mut(|__v| { + __v.prefix_inc(); + }); return (*self).clone(); } fn operator_post_inc_9(&self, mut _a0: i32) -> S { let mut old: S = (*(*self).upgrade().deref()).clone(); - field!((*self), v).with_mut(|__v| __v.prefix_inc()); + field!((*self), v).with_mut(|__v| { + __v.prefix_inc(); + }); return old; } fn operator_dec_10(&self) -> Ptr { - field!((*self), v).with_mut(|__v| __v.prefix_dec()); + field!((*self), v).with_mut(|__v| { + __v.prefix_dec(); + }); return (*self).clone(); } fn operator_post_dec_11(&self, mut _a0: i32) -> S { let mut old: S = (*(*self).upgrade().deref()).clone(); - field!((*self), v).with_mut(|__v| __v.prefix_dec()); + field!((*self), v).with_mut(|__v| { + __v.prefix_dec(); + }); return old; } } diff --git a/tests/unit/out/refcount/pair_converting_construction.rs b/tests/unit/out/refcount/pair_converting_construction.rs index ef1ad37581..de3c9114fb 100644 --- a/tests/unit/out/refcount/pair_converting_construction.rs +++ b/tests/unit/out/refcount/pair_converting_construction.rs @@ -141,7 +141,9 @@ impl Name { let __this: Value = Rc::new(RefCell::new(Self { len: 0 })); let this: Ptr = __this.as_pointer(); 'loop_: while ((elem!(s, this.with(|__s| __s.len)).read()) != 0) { - field!(this, len).with_mut(|__v| __v.prefix_inc()); + field!(this, len).with_mut(|__v| { + __v.prefix_inc(); + }); } Rc::try_unwrap(__this).ok().unwrap().into_inner() } diff --git a/tests/unit/out/refcount/random.rs b/tests/unit/out/refcount/random.rs index a1249740f0..9132c93683 100644 --- a/tests/unit/out/refcount/random.rs +++ b/tests/unit/out/refcount/random.rs @@ -241,7 +241,9 @@ pub trait PairImpl { impl PairImpl for Ptr { fn method(&self) { field!((*self), x).with_mut(|__v| __v.postfix_inc()); - field!((*self), y).with_mut(|__v| __v.prefix_inc()); + field!((*self), y).with_mut(|__v| { + __v.prefix_inc(); + }); array_elem!((*self), a, 4).write(1); (*self).with(|__s| __s.r.clone()).write(1); field!((*self), p).write(Ptr::::null()); diff --git a/tests/unit/out/refcount/static_local.rs b/tests/unit/out/refcount/static_local.rs index f022373123..019423527a 100644 --- a/tests/unit/out/refcount/static_local.rs +++ b/tests/unit/out/refcount/static_local.rs @@ -51,7 +51,7 @@ pub trait S_8Impl { } impl S_8Impl for Ptr { fn get(&self) -> i32 { - return (*x_7.with(Value::clone).borrow_mut()).prefix_inc(); + return (*(*x_7.with(Value::clone).borrow_mut()).prefix_inc()); } } pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/string.rs b/tests/unit/out/refcount/string.rs index 2e71ac2df0..f8ee8a04f1 100644 --- a/tests/unit/out/refcount/string.rs +++ b/tests/unit/out/refcount/string.rs @@ -7,7 +7,9 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; pub fn counted_string_0(calls: Ptr) -> Vec { - calls.with_mut(|__v| __v.prefix_inc()); + calls.with_mut(|__v| { + __v.prefix_inc(); + }); return { let mut __bytes = Ptr::::from_string_literal(b"hello").to_c_bytes(); __bytes.push(0); @@ -15,7 +17,9 @@ pub fn counted_string_0(calls: Ptr) -> Vec { }; } pub fn counted_ref_1(s: Ptr>, calls: Ptr) -> Ptr> { - calls.with_mut(|__v| __v.prefix_inc()); + calls.with_mut(|__v| { + __v.prefix_inc(); + }); return (s).clone(); } pub fn main() { diff --git a/tests/unit/out/refcount/string_substr.rs b/tests/unit/out/refcount/string_substr.rs index eceb7a2348..6e3db03d0f 100644 --- a/tests/unit/out/refcount/string_substr.rs +++ b/tests/unit/out/refcount/string_substr.rs @@ -14,11 +14,15 @@ pub struct Text { pub value: Ptr>, } pub fn receiver_0(s: Ptr>, calls: Ptr) -> Ptr> { - calls.with_mut(|__v| __v.prefix_inc()); + calls.with_mut(|__v| { + __v.prefix_inc(); + }); return (s).clone(); } pub fn temporary_1(calls: Ptr) -> Vec { - calls.with_mut(|__v| __v.prefix_inc()); + calls.with_mut(|__v| { + __v.prefix_inc(); + }); return { let mut __bytes = Ptr::::from_string_literal(b"hello").to_c_bytes(); __bytes.push(0); diff --git a/tests/unit/out/refcount/struct_ctor.rs b/tests/unit/out/refcount/struct_ctor.rs index a7527c6673..df0b113c6b 100644 --- a/tests/unit/out/refcount/struct_ctor.rs +++ b/tests/unit/out/refcount/struct_ctor.rs @@ -18,8 +18,12 @@ impl StructWithCtor { pub fn new(mut x1: i32, mut x2: i32) -> Self { let __this: Value = Rc::new(RefCell::new(Self { x1_: x1, x2_: x2 })); let this: Ptr = __this.as_pointer(); - field!(this, x1_).with_mut(|__v| __v.prefix_inc()); - field!(this, x2_).with_mut(|__v| __v.prefix_dec()); + field!(this, x1_).with_mut(|__v| { + __v.prefix_inc(); + }); + field!(this, x2_).with_mut(|__v| { + __v.prefix_dec(); + }); Rc::try_unwrap(__this).ok().unwrap().into_inner() } } diff --git a/tests/unit/out/refcount/sys_stat.rs b/tests/unit/out/refcount/sys_stat.rs index 9ecd89895d..185c9bf7e6 100644 --- a/tests/unit/out/refcount/sys_stat.rs +++ b/tests/unit/out/refcount/sys_stat.rs @@ -124,7 +124,9 @@ pub fn test_st_mtime_access_2() { }; assert!(((field_ptr!(sp, st_mtime).read()) == (7 as ::libc::time_t))); field_ptr!(st.as_pointer(), st_mtime).with_mut(|__v| __v.postfix_inc()); - field_ptr!(sp, st_mtime).with_mut(|__v| __v.prefix_inc()); + field_ptr!(sp, st_mtime).with_mut(|__v| { + __v.prefix_inc(); + }); assert!(((field_ptr!(st.as_pointer(), st_mtime).read()) == (9 as ::libc::time_t))); let mut mtime: Ptr<::libc::time_t> = (field_ptr!(st.as_pointer(), st_mtime)); mtime.write((10 as ::libc::time_t)); diff --git a/tests/unit/out/refcount/temporary_field_addr.rs b/tests/unit/out/refcount/temporary_field_addr.rs index 21068d1722..8f1c109548 100644 --- a/tests/unit/out/refcount/temporary_field_addr.rs +++ b/tests/unit/out/refcount/temporary_field_addr.rs @@ -56,7 +56,9 @@ impl Default for Outer { } } pub fn make_0(calls: Ptr) -> Outer { - calls.with_mut(|__v| __v.prefix_inc()); + calls.with_mut(|__v| { + __v.prefix_inc(); + }); return Outer { values: Vec::from([1, 2, 3]), inner: Inner { diff --git a/tests/unit/out/refcount/unary.rs b/tests/unit/out/refcount/unary.rs index 0c889c4195..d6d02ff66d 100644 --- a/tests/unit/out/refcount/unary.rs +++ b/tests/unit/out/refcount/unary.rs @@ -18,10 +18,10 @@ fn main_0() -> i32 { } let mut out: i32 = 0; 'loop_: while (x != 0) { - out += a[(x.prefix_dec()) as usize]; + out += a[(*x.prefix_dec()) as usize]; } out.postfix_inc(); - let mut x2: i32 = out.prefix_dec(); + let mut x2: i32 = (*out.prefix_dec()); out.prefix_inc(); let mut x3: i32 = out.postfix_dec(); assert!((((out.postfix_inc() + x2) + x3) == 19)); @@ -33,9 +33,9 @@ fn main_0() -> i32 { assert!((a[(0) as usize] == a[(0) as usize])); let mut wide: i128 = 5_i128; let mut w1: i128 = wide.postfix_inc(); - let mut w2: i128 = wide.prefix_inc(); + let mut w2: i128 = (*wide.prefix_inc()); let mut w3: i128 = wide.postfix_dec(); - let mut w4: i128 = wide.prefix_dec(); + let mut w4: i128 = (*wide.prefix_dec()); assert!((((w1 == 5_i128) && (w2 == 7_i128)) && (w3 == 7_i128)) && (w4 == 5_i128)); let mut uwide: u128 = 0_u128; uwide.prefix_dec(); diff --git a/tests/unit/out/refcount/unboxed_conditional_iterator.rs b/tests/unit/out/refcount/unboxed_conditional_iterator.rs index 9ce447185f..607ae27451 100644 --- a/tests/unit/out/refcount/unboxed_conditional_iterator.rs +++ b/tests/unit/out/refcount/unboxed_conditional_iterator.rs @@ -34,7 +34,9 @@ pub fn assign_2(mut c: bool, mut v: i32) -> i32 { } else { (b.as_pointer()) } - .with_mut(|__v| __v.prefix_inc()); + .with_mut(|__v| { + __v.prefix_inc(); + }); return (((*a.borrow()) * 10) + (*b.borrow())); } pub fn lehmer_3(mut sigma: Ptr, mut len: u32, mut code: Ptr) { @@ -89,7 +91,12 @@ pub fn sum_4(v: Ptr>) -> i32 { let it: Value> = Rc::new(RefCell::new(v.decay().begin())); 'loop_: while (*it.borrow()) != v.decay().end() { s += ((*it.borrow()).iter_deref().read()); - (*it.borrow_mut()).iter_inc(); + { + it.as_pointer().with_mut(|__it| { + __it.iter_inc(); + }); + it.as_pointer() + }; } } return s; diff --git a/tests/unit/out/refcount/unboxed_locals.rs b/tests/unit/out/refcount/unboxed_locals.rs index ce4c4035a6..fcdf63ed92 100644 --- a/tests/unit/out/refcount/unboxed_locals.rs +++ b/tests/unit/out/refcount/unboxed_locals.rs @@ -10,7 +10,9 @@ pub fn set_0(mut p: Ptr, mut v: i32) { p.write({ v }); } pub fn inc_1(r: Ptr) { - r.with_mut(|__v| __v.prefix_inc()); + r.with_mut(|__v| { + __v.prefix_inc(); + }); } #[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] #[byte_size(8)] diff --git a/tests/unit/out/refcount/unboxed_records.rs b/tests/unit/out/refcount/unboxed_records.rs index ad65de18bd..09885dadb6 100644 --- a/tests/unit/out/refcount/unboxed_records.rs +++ b/tests/unit/out/refcount/unboxed_records.rs @@ -127,7 +127,9 @@ pub trait CounterImpl { } impl CounterImpl for Ptr { fn inc(&self) { - field!((*self), n).with_mut(|__v| __v.prefix_inc()); + field!((*self), n).with_mut(|__v| { + __v.prefix_inc(); + }); } } pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/unique_ptr.rs b/tests/unit/out/refcount/unique_ptr.rs index c6408209fd..52b757bd16 100644 --- a/tests/unit/out/refcount/unique_ptr.rs +++ b/tests/unit/out/refcount/unique_ptr.rs @@ -34,7 +34,9 @@ pub fn DoStuffWithSafePointer_0(safe_ptr: Ptr>>) { x2.as_pointer().write(1); x1.as_pointer().write(x2.take()); let mut raw_ptr1: Ptr = ((*x1.borrow()).as_pointer()); - raw_ptr1.with_mut(|__v| __v.prefix_inc()); + raw_ptr1.with_mut(|__v| { + __v.prefix_inc(); + }); ({ field_ptr!(((*safe_ptr.upgrade().deref()).as_pointer()), ptr) }) .write((*x1.borrow_mut()).take()); ({ SafePointerImpl::inc(&((*safe_ptr.upgrade().deref()).as_pointer())) }); @@ -225,7 +227,9 @@ impl SafePointerImpl for Ptr { (*self) .with(|__s| __s.ptr.clone()) .as_pointer() - .with_mut(|__v| __v.prefix_inc()); + .with_mut(|__v| { + __v.prefix_inc(); + }); } fn move_assign(&self, _a0: Ptr) -> Ptr { field_ptr!((*self), ptr) diff --git a/tests/unit/out/refcount/vector3.rs b/tests/unit/out/refcount/vector3.rs index eeeec88937..dfe986a893 100644 --- a/tests/unit/out/refcount/vector3.rs +++ b/tests/unit/out/refcount/vector3.rs @@ -31,7 +31,9 @@ fn main_0() -> i32 { let v2: Ptr> = v2.iter_deref(); 'loop_: for i in IterRange::new(v2.decay().begin(), v2.decay().end()) { let i: Ptr = i.iter_deref(); - i.with_mut(|__v| __v.prefix_inc()); + i.with_mut(|__v| { + __v.prefix_inc(); + }); } } 'loop_: for v2 in IterRange::new(v.decay().begin(), v.decay().end()) { diff --git a/tests/unit/out/refcount/vector_iterator_arg_side_effects.rs b/tests/unit/out/refcount/vector_iterator_arg_side_effects.rs index 4365214b3e..1e40b7db56 100644 --- a/tests/unit/out/refcount/vector_iterator_arg_side_effects.rs +++ b/tests/unit/out/refcount/vector_iterator_arg_side_effects.rs @@ -13,7 +13,12 @@ pub fn main() { fn main_0() -> i32 { let v: Value> = Rc::new(RefCell::new(Vec::from([1, 2, 3, 4]))); let it: Value> = Rc::new(RefCell::new(v.decay().begin())); - (*it.borrow_mut()).iter_inc(); + { + it.as_pointer().with_mut(|__it| { + __it.iter_inc(); + }); + it.as_pointer() + }; let r: Value> = Rc::new(RefCell::new( match ({ >::from((*it.borrow_mut()).iter_post_inc()) },) { (mut __tmp_0,) => { @@ -57,6 +62,91 @@ fn main_0() -> i32 { == 1) && (i == 2) ); + let w: Value> = Rc::new(RefCell::new(Vec::from([10, 20, 30, 40]))); + let a: Value> = Rc::new(RefCell::new(w.decay().end())); + let ra: Ptr> = ({ + a.as_pointer().with_mut(|__it| { + __it.iter_add_assign(-3_isize); + }); + a.as_pointer() + }); + assert!( + ({ + ({ (ra).clone() } == { (a.as_pointer()) }) + && (((*a.borrow()).iter_deref().read()) == 20) + }) + ); + let rb: Ptr> = { + a.as_pointer().with_mut(|__it| { + __it.iter_inc(); + }); + a.as_pointer() + }; + assert!( + ({ + ({ (rb).clone() } == { (a.as_pointer()) }) + && (((*a.borrow()).iter_deref().read()) == 30) + }) + ); + let rc: Ptr> = { + a.as_pointer().with_mut(|__it| { + __it.iter_dec(); + }); + a.as_pointer() + }; + assert!( + ({ + ({ (rc).clone() } == { (a.as_pointer()) }) + && (((*a.borrow()).iter_deref().read()) == 20) + }) + ); + let rd: Ptr> = ({ + a.as_pointer().with_mut(|__it| { + __it.iter_add_assign(2_isize); + }); + a.as_pointer() + }); + assert!( + ({ + ({ (rd).clone() } == { (a.as_pointer()) }) + && (((*a.borrow()).iter_deref().read()) == 40) + }) + ); + let b: Value> = Rc::new(RefCell::new(w.decay().begin())); + let mut x: i32 = ((*{ + b.as_pointer().with_mut(|__it| { + __it.iter_inc(); + }); + b.as_pointer() + } + .upgrade() + .deref()) + .iter_deref() + .read()); + assert!((x == 20)); + let k: Value> = Rc::new(RefCell::new( + (*{ + b.as_pointer().with_mut(|__it| { + __it.iter_inc(); + }); + b.as_pointer() + } + .upgrade() + .deref()) + .clone(), + )); + { + k.as_pointer().with_mut(|__it| { + __it.iter_inc(); + }); + k.as_pointer() + }; + assert!( + ({ + (((*k.borrow()).iter_deref().read()) == 40) + && (((*b.borrow()).iter_deref().read()) == 30) + }) + ); return 0; } pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/alloc_array.rs b/tests/unit/out/unsafe/alloc_array.rs index 5035baee67..a8fff9576f 100644 --- a/tests/unit/out/unsafe/alloc_array.rs +++ b/tests/unit/out/unsafe/alloc_array.rs @@ -23,7 +23,7 @@ pub unsafe fn All_0(arr: *mut Option>, mut N: i32, mut element: i32) pub unsafe fn Consume_1(mut arr: Option>, mut N: i32) -> i32 { let mut sum: i32 = 0; let mut i: i32 = -1_i32; - 'loop_: while ((i.prefix_inc()) < (N)) { + 'loop_: while ((*i.prefix_inc()) < (N)) { sum += (*arr .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) diff --git a/tests/unit/out/unsafe/complex_function.rs b/tests/unit/out/unsafe/complex_function.rs index d9481c5727..873354eacf 100644 --- a/tests/unit/out/unsafe/complex_function.rs +++ b/tests/unit/out/unsafe/complex_function.rs @@ -107,7 +107,7 @@ unsafe fn main_0() -> i32 { .v, ) })); - let mut bar_inc: i32 = (*(unsafe { bar_2(&mut x1) })).prefix_inc(); + let mut bar_inc: i32 = (*(*(unsafe { bar_2(&mut x1) })).prefix_inc()); bar_inc = (*(unsafe { bar_2(&mut x1) })).postfix_inc(); bar_inc = (((*(unsafe { bar_2(&mut x1) })) + (unsafe { foo_0(x4) })) + (1)); (*(unsafe { @@ -127,7 +127,7 @@ unsafe fn main_0() -> i32 { ) })) .postfix_inc(); - let mut bar_inc2: i32 = (*(unsafe { + let mut bar_inc2: i32 = (*(*(unsafe { bar_2( &mut (*(unsafe { X2::get(&mut (*(unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }))) @@ -135,7 +135,7 @@ unsafe fn main_0() -> i32 { .v, ) })) - .prefix_inc(); + .prefix_inc()); bar_inc2 = (*(unsafe { bar_2( &mut (*(unsafe { diff --git a/tests/unit/out/unsafe/container_element_receiver.rs b/tests/unit/out/unsafe/container_element_receiver.rs index 784f4c00e1..5e28fa0b06 100644 --- a/tests/unit/out/unsafe/container_element_receiver.rs +++ b/tests/unit/out/unsafe/container_element_receiver.rs @@ -30,7 +30,10 @@ pub unsafe fn sum_1(v: *const Vec) -> i32 { let mut it: UnsafeRandomAccessIterator = (*v).begin(); 'loop_: while it != (*v).end() { total += (*it.iter_deref()); - it.iter_inc(); + { + (*(&mut it as *mut UnsafeRandomAccessIterator)).iter_inc(); + (&mut it as *mut UnsafeRandomAccessIterator) + }; } } return ((total) diff --git a/tests/unit/out/unsafe/default_function_arguments.rs b/tests/unit/out/unsafe/default_function_arguments.rs index cbf7612ed0..8e38f82b2f 100644 --- a/tests/unit/out/unsafe/default_function_arguments.rs +++ b/tests/unit/out/unsafe/default_function_arguments.rs @@ -34,7 +34,7 @@ impl Default for Bar { } pub static mut counter_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub unsafe fn next_3() -> i32 { - return (*std::cell::LazyCell::force_mut(&mut *&raw mut counter_2)).prefix_inc(); + return (*(*std::cell::LazyCell::force_mut(&mut *&raw mut counter_2)).prefix_inc()); } pub unsafe fn lazy_4(mut x: Option) -> i32 { let mut x: i32 = x.unwrap_or_else(|| unsafe { (unsafe { next_3() }) }); diff --git a/tests/unit/out/unsafe/enum_increment.rs b/tests/unit/out/unsafe/enum_increment.rs index 8c80c18390..c872595f77 100644 --- a/tests/unit/out/unsafe/enum_increment.rs +++ b/tests/unit/out/unsafe/enum_increment.rs @@ -29,9 +29,9 @@ unsafe fn main_0() -> i32 { assert!(((count) == (3))); let mut c: color = color_RED; assert!(((c.postfix_inc() as u32) == ((color_RED as i32) as u32))); - assert!(((c.prefix_inc() as u32) == ((color_BLUE as i32) as u32))); + assert!((((*c.prefix_inc()) as u32) == ((color_BLUE as i32) as u32))); assert!(((c.postfix_dec() as u32) == ((color_BLUE as i32) as u32))); - assert!(((c.prefix_dec() as u32) == ((color_RED as i32) as u32))); + assert!((((*c.prefix_dec()) as u32) == ((color_RED as i32) as u32))); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/foreach_mut.rs b/tests/unit/out/unsafe/foreach_mut.rs index 3b6869788f..c9aacaac36 100644 --- a/tests/unit/out/unsafe/foreach_mut.rs +++ b/tests/unit/out/unsafe/foreach_mut.rs @@ -29,7 +29,7 @@ unsafe fn main_0() -> i32 { let mut sum: i32 = 0; 'loop_: for x in IterRange::new(v1.begin(), v1.end()) { let mut x: i32 = (*x.iter_deref()); - sum += x.prefix_inc(); + sum += (*x.prefix_inc()); } 'loop_: for x in IterRange::new(v1.begin(), v1.end()) { let x: i32 = (*x.iter_deref()); diff --git a/tests/unit/out/unsafe/global_non_const_init.rs b/tests/unit/out/unsafe/global_non_const_init.rs index 2479407cbe..4114f473d4 100644 --- a/tests/unit/out/unsafe/global_non_const_init.rs +++ b/tests/unit/out/unsafe/global_non_const_init.rs @@ -7,7 +7,7 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub unsafe fn next_0() -> i32 { - return (*std::cell::LazyCell::force_mut(&mut *&raw mut counter_1)).prefix_inc(); + return (*(*std::cell::LazyCell::force_mut(&mut *&raw mut counter_1)).prefix_inc()); } static mut counter_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub unsafe fn marker_2(mut tag: u8) -> u8 { diff --git a/tests/unit/out/unsafe/lambda_capture_library_types.rs b/tests/unit/out/unsafe/lambda_capture_library_types.rs index 169d7c236d..e4d116ccbd 100644 --- a/tests/unit/out/unsafe/lambda_capture_library_types.rs +++ b/tests/unit/out/unsafe/lambda_capture_library_types.rs @@ -53,7 +53,7 @@ unsafe fn main_0() -> i32 { let n: i32 = n; }, || -> i32 { - return n.prefix_inc(); + return (*n.prefix_inc()); } ); let mut outer: FnPtr i32> = lambda_unsafe!( diff --git a/tests/unit/out/unsafe/lambda_static_local.rs b/tests/unit/out/unsafe/lambda_static_local.rs index 71753b4e08..20194f2993 100644 --- a/tests/unit/out/unsafe/lambda_static_local.rs +++ b/tests/unit/out/unsafe/lambda_static_local.rs @@ -16,7 +16,7 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut next: FnPtr i32> = FnPtr:: i32>::new(|| -> i32 { unsafe { - return (*std::cell::LazyCell::force_mut(&mut *&raw mut n_1)).prefix_inc(); + return (*(*std::cell::LazyCell::force_mut(&mut *&raw mut n_1)).prefix_inc()); } }); assert!(((unsafe { next.call() }) == (1))); @@ -26,7 +26,7 @@ unsafe fn main_0() -> i32 { assert!(((unsafe { next.call() }) == (4))); let mut fresh: FnPtr i32> = FnPtr:: i32>::new(|| -> i32 { unsafe { - return (*std::cell::LazyCell::force_mut(&mut *&raw mut n_1)).prefix_inc(); + return (*(*std::cell::LazyCell::force_mut(&mut *&raw mut n_1)).prefix_inc()); } }); assert!(((unsafe { fresh.call() }) == (5))); diff --git a/tests/unit/out/unsafe/map.rs b/tests/unit/out/unsafe/map.rs index 1d21b475ef..46a149db19 100644 --- a/tests/unit/out/unsafe/map.rs +++ b/tests/unit/out/unsafe/map.rs @@ -229,6 +229,23 @@ unsafe fn main_0() -> i32 { assert!((((*points.subscript_move(&mut 8, |__k| cpp_move_unsafe!(__k))).x) == (5))); assert!((((*points.subscript_move(&mut 8, |__k| cpp_move_unsafe!(__k))).y) == (6))); assert!(((points.len()) == (2_usize))); + let mut mi: UnsafeBidirectionalIterator<(i32, i32)> = m3.begin(); + let mr: *mut UnsafeBidirectionalIterator<(i32, i32)> = &mut (*{ + (*(&mut mi as *mut UnsafeBidirectionalIterator<(i32, i32)>)).iter_inc(); + (&mut mi as *mut UnsafeBidirectionalIterator<(i32, i32)>) + }); + assert!( + ((mr) == (&mut mi as *mut UnsafeBidirectionalIterator<(i32, i32)>)) + && (((*mi.iter_deref()).0) == (4)) + ); + let md: *mut UnsafeBidirectionalIterator<(i32, i32)> = &mut (*{ + (*(&mut mi as *mut UnsafeBidirectionalIterator<(i32, i32)>)).iter_dec(); + (&mut mi as *mut UnsafeBidirectionalIterator<(i32, i32)>) + }); + assert!( + ((md) == (&mut mi as *mut UnsafeBidirectionalIterator<(i32, i32)>)) + && (((*mi.iter_deref()).0) == (1)) + ); k = 0; let value_0: *const u32 = &raw const (*m.get(&(k as i16)).expect("out of range!")).1; assert!( diff --git a/tests/unit/out/unsafe/static_local.rs b/tests/unit/out/unsafe/static_local.rs index 15b480a54e..3343b044dd 100644 --- a/tests/unit/out/unsafe/static_local.rs +++ b/tests/unit/out/unsafe/static_local.rs @@ -26,7 +26,7 @@ static mut x_7: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { pub struct S_8 {} impl S_8 { pub unsafe fn get(&self) -> i32 { - return (*std::cell::LazyCell::force_mut(&mut *&raw mut x_7)).prefix_inc(); + return (*(*std::cell::LazyCell::force_mut(&mut *&raw mut x_7)).prefix_inc()); } } pub fn main() { diff --git a/tests/unit/out/unsafe/unary.rs b/tests/unit/out/unsafe/unary.rs index ba63401306..22d6b64325 100644 --- a/tests/unit/out/unsafe/unary.rs +++ b/tests/unit/out/unsafe/unary.rs @@ -20,10 +20,10 @@ unsafe fn main_0() -> i32 { } let mut out: i32 = 0; 'loop_: while (x != 0) { - out += a[(x.prefix_dec()) as usize]; + out += a[(*x.prefix_dec()) as usize]; } out.postfix_inc(); - let mut x2: i32 = out.prefix_dec(); + let mut x2: i32 = (*out.prefix_dec()); out.prefix_inc(); let mut x3: i32 = out.postfix_dec(); assert!(((((out.postfix_inc()) + (x2)) + (x3)) == (19))); @@ -35,9 +35,9 @@ unsafe fn main_0() -> i32 { assert!(((a[(0) as usize]) == (a[(0) as usize]))); let mut wide: i128 = 5_i128; let mut w1: i128 = wide.postfix_inc(); - let mut w2: i128 = wide.prefix_inc(); + let mut w2: i128 = (*wide.prefix_inc()); let mut w3: i128 = wide.postfix_dec(); - let mut w4: i128 = wide.prefix_dec(); + let mut w4: i128 = (*wide.prefix_dec()); assert!( ((((w1) == (5_i128)) && ((w2) == (7_i128))) && ((w3) == (7_i128))) && ((w4) == (5_i128)) ); diff --git a/tests/unit/out/unsafe/unboxed_conditional_iterator.rs b/tests/unit/out/unsafe/unboxed_conditional_iterator.rs index 1bf847c7b0..2a86c65af7 100644 --- a/tests/unit/out/unsafe/unboxed_conditional_iterator.rs +++ b/tests/unit/out/unsafe/unboxed_conditional_iterator.rs @@ -81,7 +81,10 @@ pub unsafe fn sum_4(v: *mut Vec) -> i32 { let mut it: UnsafeRandomAccessIterator = (*v).begin(); 'loop_: while it != (*v).end() { s += (*it.iter_deref()); - it.iter_inc(); + { + (*(&mut it as *mut UnsafeRandomAccessIterator)).iter_inc(); + (&mut it as *mut UnsafeRandomAccessIterator) + }; } } return s; diff --git a/tests/unit/out/unsafe/vector_iterator_arg_side_effects.rs b/tests/unit/out/unsafe/vector_iterator_arg_side_effects.rs index 5bc7334741..9ffbe68892 100644 --- a/tests/unit/out/unsafe/vector_iterator_arg_side_effects.rs +++ b/tests/unit/out/unsafe/vector_iterator_arg_side_effects.rs @@ -15,7 +15,10 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut v: Vec = Vec::from([1, 2, 3, 4]); let mut it: UnsafeRandomAccessIterator = v.begin(); - it.iter_inc(); + { + (*(&mut it as *mut UnsafeRandomAccessIterator)).iter_inc(); + (&mut it as *mut UnsafeRandomAccessIterator) + }; let mut r: UnsafeRandomAccessIterator = match ({ >::from(it.iter_post_inc()) },) { (mut __tmp_0,) => { @@ -51,6 +54,53 @@ unsafe fn main_0() -> i32 { }) == (1)) && ((i) == (2)) ); + let mut w: Vec = Vec::from([10, 20, 30, 40]); + let mut a: UnsafeRandomAccessIterator = w.end(); + let ra: *mut UnsafeRandomAccessIterator = &mut (*{ + (*(&mut a as *mut UnsafeRandomAccessIterator)).iter_add_assign(-3_isize); + (&mut a as *mut UnsafeRandomAccessIterator) + }); + assert!( + ((ra) == (&mut a as *mut UnsafeRandomAccessIterator)) && ((*a.iter_deref()) == (20)) + ); + let rb: *mut UnsafeRandomAccessIterator = &mut (*{ + (*(&mut a as *mut UnsafeRandomAccessIterator)).iter_inc(); + (&mut a as *mut UnsafeRandomAccessIterator) + }); + assert!( + ((rb) == (&mut a as *mut UnsafeRandomAccessIterator)) && ((*a.iter_deref()) == (30)) + ); + let rc: *mut UnsafeRandomAccessIterator = &mut (*{ + (*(&mut a as *mut UnsafeRandomAccessIterator)).iter_dec(); + (&mut a as *mut UnsafeRandomAccessIterator) + }); + assert!( + ((rc) == (&mut a as *mut UnsafeRandomAccessIterator)) && ((*a.iter_deref()) == (20)) + ); + let rd: *mut UnsafeRandomAccessIterator = &mut (*{ + (*(&mut a as *mut UnsafeRandomAccessIterator)).iter_add_assign(2_isize); + (&mut a as *mut UnsafeRandomAccessIterator) + }); + assert!( + ((rd) == (&mut a as *mut UnsafeRandomAccessIterator)) && ((*a.iter_deref()) == (40)) + ); + let mut b: UnsafeRandomAccessIterator = w.begin(); + let mut x: i32 = (*(*{ + (*(&mut b as *mut UnsafeRandomAccessIterator)).iter_inc(); + (&mut b as *mut UnsafeRandomAccessIterator) + }) + .iter_deref()); + assert!(((x) == (20))); + let mut k: UnsafeRandomAccessIterator = (*{ + (*(&mut b as *mut UnsafeRandomAccessIterator)).iter_inc(); + (&mut b as *mut UnsafeRandomAccessIterator) + }) + .clone(); + { + (*(&mut k as *mut UnsafeRandomAccessIterator)).iter_inc(); + (&mut k as *mut UnsafeRandomAccessIterator) + }; + assert!(((*k.iter_deref()) == (40)) && ((*b.iter_deref()) == (30))); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/vector_iterator_arg_side_effects.cpp b/tests/unit/vector_iterator_arg_side_effects.cpp index e8807d4488..46d3cf8bfe 100644 --- a/tests/unit/vector_iterator_arg_side_effects.cpp +++ b/tests/unit/vector_iterator_arg_side_effects.cpp @@ -14,5 +14,21 @@ int main() { const std::vector &c = v; int i = 1; assert(c.at(i++) == 1 && i == 2); + std::vector w = {10, 20, 30, 40}; + auto a = w.end(); + auto &ra = (a -= 3); + assert(&ra == &a && *a == 20); + auto &rb = ++a; + assert(&rb == &a && *a == 30); + auto &rc = --a; + assert(&rc == &a && *a == 20); + auto &rd = (a += 2); + assert(&rd == &a && *a == 40); + auto b = w.begin(); + int x = *++b; + assert(x == 20); + auto k = ++b; + ++k; + assert(*k == 40 && *b == 30); return 0; }