Skip to content

Commit 21abfb0

Browse files
committed
work
1 parent 3f30d90 commit 21abfb0

3 files changed

Lines changed: 33 additions & 2 deletions

File tree

‎cpp2rust/converter/converter.cpp‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2761,7 +2761,11 @@ void Converter::ConvertBinaryOperator(clang::BinaryOperator *expr) {
27612761
Convert(lhs);
27622762
}
27632763
StrCat(token::kSemiColon);
2764-
Convert(rhs);
2764+
if (isRValue()) {
2765+
StrCat(ConvertFreshRValue(rhs));
2766+
} else {
2767+
Convert(rhs);
2768+
}
27652769
} else if (IsUnsignedArithOp(expr)) {
27662770
if (expr->isCompoundAssignmentOp()) {
27672771
Convert(lhs);

‎cpp2rust/converter/models/converter_refcount.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ ConverterRefCount::MaterializeTemp(const std::string &binding_name,
496496
clang::QualType param_type,
497497
clang::Expr *expr) {
498498
auto pointee = param_type.getNonReferenceType();
499-
auto value = ConvertRValue(expr, pointee);
499+
auto value = ConvertFreshRValue(expr, pointee);
500500
auto type_str = ToStringBase(pointee);
501501
const auto *decl = in_const_initializer_ ? keyword::kStatic : keyword::kLet;
502502

‎tests/unit/comma_operator.cpp‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
#include <cassert>
2+
#include <vector>
3+
4+
struct Pair {
5+
int first;
6+
int second;
7+
};
8+
9+
long twice(const long &v) { return v * 2; }
10+
11+
int sum(const Pair &p) { return p.first + p.second; }
212

313
int main() {
414
int x = 1;
@@ -20,5 +30,22 @@ int main() {
2030
assert(b == 2);
2131
}
2232

33+
std::vector<int> v1 = {1, 2};
34+
std::vector<int> v2 = (a = 5, v1);
35+
v2.push_back(3);
36+
assert(a == 5);
37+
assert(v1.size() == 2);
38+
assert(v2.size() == 3);
39+
40+
Pair p1{1, 2};
41+
Pair p2 = (b = 6, p1);
42+
p2.first = 10;
43+
assert(p1.first == 1);
44+
assert(p2.first == 10);
45+
46+
assert(twice(a) == 10);
47+
assert(sum((a = 7, p1)) == 3);
48+
assert(a == 7);
49+
2350
return 0;
2451
}

0 commit comments

Comments
 (0)