Skip to content

Commit 48f643a

Browse files
committed
fix(to_cpp1): extend move supression to member access
1 parent 61550a5 commit 48f643a

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

regression-tests/mixed-parameter-passing-with-forward.cpp2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,20 @@ parameter_styles: (
1414
)
1515
= {
1616
z: int = 12;
17+
y: std::pair = (17, 29);
1718

1819
z++;
20+
y.first--;
1921
b += "plugh";
2022

2123
if std::rand()%2 {
2224
z++;
25+
y.first--;
2326
copy_from(b); // definite last use
2427
}
2528
else {
2629
copy_from(b&); // NB: better not move from this (why not?)
30+
copy_from(y.second&); // Ditto
2731
copy_from(d);
2832
copy_from(z++);
2933
copy_from(e);

regression-tests/test-results/mixed-parameter-passing-with-forward.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ CPP2_REQUIRES (std::is_same_v<CPP2_TYPEOF(e), std::string>)
2828
#line 8 "mixed-parameter-passing-with-forward.cpp2"
2929
;
3030

31-
#line 42 "mixed-parameter-passing-with-forward.cpp2"
31+
#line 46 "mixed-parameter-passing-with-forward.cpp2"
3232
[[nodiscard]] auto main() -> int;
3333

3434

@@ -49,16 +49,20 @@ requires (std::is_same_v<CPP2_TYPEOF(e), std::string>)
4949
#line 15 "mixed-parameter-passing-with-forward.cpp2"
5050
{
5151
int z {12};
52+
std::pair y {17, 29};
5253

5354
++z;
55+
--y.first;
5456
b += "plugh";
5557

5658
if (std::rand() % 2) {
5759
++z;
60+
--y.first;
5861
copy_from(std::move(b));// definite last use
5962
}
6063
else {
6164
copy_from(&b); // NB: better not move from this (why not?)
65+
copy_from(&y.second); // Ditto
6266
copy_from(std::move(d));
6367
copy_from(++z);
6468
copy_from(CPP2_FORWARD(e));

source/to_cpp1.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3157,6 +3157,16 @@ class cppfront
31573157
n.ops.front().op->type() == lexeme::MinusMinus
31583158
|| n.ops.front().op->type() == lexeme::PlusPlus
31593159
|| n.ops.front().op->type() == lexeme::Ampersand
3160+
|| (
3161+
std::ssize(n.ops) >= 2
3162+
&& n.ops.front().op->type() == lexeme::Dot
3163+
&&
3164+
(
3165+
n.ops[1].op->type() == lexeme::MinusMinus
3166+
|| n.ops[1].op->type() == lexeme::PlusPlus
3167+
|| n.ops[1].op->type() == lexeme::Ampersand
3168+
)
3169+
)
31603170
)
31613171
{
31623172
suppress_move_from_last_use = true;

0 commit comments

Comments
 (0)