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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cpp2rust/converter/converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2875,6 +2875,13 @@ bool Converter::VisitExplicitCastExpr(clang::ExplicitCastExpr *expr) {

bool Converter::VisitCXXRewrittenBinaryOperator(
clang::CXXRewrittenBinaryOperator *expr) {
if (Mapper::Contains(ctx_, expr)) {
auto decomposed = expr->getDecomposedForm();
clang::Expr *args[] = {const_cast<clang::Expr *>(decomposed.LHS),
const_cast<clang::Expr *>(decomposed.RHS)};
StrCat(GetMappedAsString(expr, args, 2, nullptr));
return false;
}
Convert(expr->getSemanticForm());
return false;
}
Expand Down
29 changes: 29 additions & 0 deletions rules/pair/src_cxx20.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2022-present INESC-ID.
// Distributed under the MIT license that can be found in the LICENSE file.

#include <utility>

template <typename T1, typename T2>
bool f28(const std::pair<T1, T2> &a0, const std::pair<T1, T2> &a1) {
return a0 != a1;
}

template <typename T1, typename T2>
bool f29(const std::pair<T1, T2> &a0, const std::pair<T1, T2> &a1) {
return a0 < a1;
}

template <typename T1, typename T2>
bool f30(const std::pair<T1, T2> &a0, const std::pair<T1, T2> &a1) {
return a0 <= a1;
}

template <typename T1, typename T2>
bool f31(const std::pair<T1, T2> &a0, const std::pair<T1, T2> &a1) {
return a0 > a1;
}

template <typename T1, typename T2>
bool f32(const std::pair<T1, T2> &a0, const std::pair<T1, T2> &a1) {
return a0 >= a1;
}
20 changes: 20 additions & 0 deletions rules/pair/tgt_unsafe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,23 @@ where
{
&*a0.get::<T1>()
}

unsafe fn f28<T1: PartialEq, T2: PartialEq>(a0: (T1, T2), a1: (T1, T2)) -> bool {
a0 != a1
}

unsafe fn f29<T1: PartialOrd, T2: PartialOrd>(a0: (T1, T2), a1: (T1, T2)) -> bool {
a0 < a1
}

unsafe fn f30<T1: PartialOrd, T2: PartialOrd>(a0: (T1, T2), a1: (T1, T2)) -> bool {
a0 <= a1
}

unsafe fn f31<T1: PartialOrd, T2: PartialOrd>(a0: (T1, T2), a1: (T1, T2)) -> bool {
a0 > a1
}

unsafe fn f32<T1: PartialOrd, T2: PartialOrd>(a0: (T1, T2), a1: (T1, T2)) -> bool {
a0 >= a1
}
28 changes: 28 additions & 0 deletions tests/std/utilities/pairs/out/refcount/pairs.pair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,33 @@ pub fn test_3() {
assert!(({ (((*(*target.borrow()).1.borrow()).as_pointer().read()) == 9) }));
assert!(({ ((*(*source.borrow()).1.borrow()).as_pointer()).is_null() }));
}
pub fn test_4() {
let a: Value<(Value<i32>, Value<i32>)> = Rc::new(RefCell::new((
Rc::new(RefCell::new(1)),
Rc::new(RefCell::new(2)),
)));
let b: Value<(Value<i32>, Value<i32>)> = Rc::new(RefCell::new((
Rc::new(RefCell::new(1)),
Rc::new(RefCell::new(3)),
)));
let c: Value<(Value<i32>, Value<i32>)> = Rc::new(RefCell::new((
Rc::new(RefCell::new(2)),
Rc::new(RefCell::new(0)),
)));
assert!((*a.borrow()) != (*b.borrow()));
assert!(({ !((*a.borrow()) != (*a.borrow())) }));
assert!((*a.borrow()) < (*b.borrow()));
assert!(({ !((*b.borrow()) < (*a.borrow())) }));
assert!((*b.borrow()) < (*c.borrow()));
assert!((*a.borrow()) <= (*a.borrow()));
assert!(({ !((*c.borrow()) <= (*b.borrow())) }));
assert!((*c.borrow()) > (*b.borrow()));
assert!(({ !((*a.borrow()) > (*a.borrow())) }));
assert!((*c.borrow()) >= (*a.borrow()));
assert!(({ !((*a.borrow()) >= (*b.borrow())) }));
let mut ordered: bool = ((*a.borrow()) < (*b.borrow())) && ((*b.borrow()) < (*c.borrow()));
assert!(ordered);
}
pub fn main() {
__cpp2rust_init_globals();
std::process::exit(main_0());
Expand All @@ -127,6 +154,7 @@ fn main_0() -> i32 {
({ test_1() });
({ test_2() });
({ test_3() });
({ test_4() });
return 0;
}
pub fn __cpp2rust_init_globals() {}
19 changes: 19 additions & 0 deletions tests/std/utilities/pairs/out/unsafe/pairs.pair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,24 @@ pub unsafe fn test_3() {
.is_null()
);
}
pub unsafe fn test_4() {
let mut a: (i32, i32) = (1, 2);
let mut b: (i32, i32) = (1, 3);
let mut c: (i32, i32) = (2, 0);
assert!(a != b);
assert!(!(a != a));
assert!(a < b);
assert!(!(b < a));
assert!(b < c);
assert!(a <= a);
assert!(!(c <= b));
assert!(c > b);
assert!(!(a > a));
assert!(c >= a);
assert!(!(a >= b));
let mut ordered: bool = (a < b) && (b < c);
assert!(ordered);
}
pub fn main() {
unsafe {
__cpp2rust_init_globals();
Expand All @@ -144,6 +162,7 @@ unsafe fn main_0() -> i32 {
(unsafe { test_1() });
(unsafe { test_2() });
(unsafe { test_3() });
(unsafe { test_4() });
return 0;
}
pub unsafe fn __cpp2rust_init_globals() {}
32 changes: 32 additions & 0 deletions tests/std/utilities/pairs/pairs.pair.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,42 @@ void test() {
}
} // namespace p40_converting_move_assignment

// N4950 [over.match.oper]/3.4: The rewritten candidate set is determined as
// follows:
// (3.4.1) For the relational (7.6.9) operators, the rewritten candidates
// include all non-rewritten candidates for the expression x <=> y.
// (3.4.3) For the != operator (7.6.10), the rewritten candidates include all
// non-rewritten candidates for the expression x == y that are rewrite targets
// with first operand x (see below).
// N4950 [over.match.oper]/8: The argument list contains all of the operands of
// the operator. The best function from the set of candidate functions is
// selected according to 12.2.3 and 12.2.4.
namespace over_match_oper_p3_4_rewritten_candidates {
void test() {
std::pair<int, int> a(1, 2);
std::pair<int, int> b(1, 3);
std::pair<int, int> c(2, 0);
assert(a != b);
assert(!(a != a));
assert(a < b);
assert(!(b < a));
assert(b < c);
assert(a <= a);
assert(!(c <= b));
assert(c > b);
assert(!(a > a));
assert(c >= a);
assert(!(a >= b));
bool ordered = a < b && b < c;
assert(ordered);
}
} // namespace over_match_oper_p3_4_rewritten_candidates

int main() {
p2_move_constructor::test();
p12_forwarding_constructor::test();
p16_converting_move_constructor::test();
p40_converting_move_assignment::test();
over_match_oper_p3_4_rewritten_candidates::test();
return 0;
}
Loading