Skip to content

Commit cbcd5a0

Browse files
committed
fix(cpp1): extend move supression to member access
1 parent efd185f commit cbcd5a0

8 files changed

+26
-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);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
clang version 18.0.0 (https://github.com/llvm/llvm-project.git 3723ede3cf5324827f8fbbe7f484c2ee4d7a7204)
2+
Target: x86_64-pc-linux-gnu
3+
Thread model: posix
4+
InstalledDir: /home/johel/root/clang-main/bin

regression-tests/test-results/clang-18/pure2-bugfix-for-non-local-function-expression.cpp.execution

Whitespace-only changes.

regression-tests/test-results/clang-18/pure2-bugfix-for-non-local-function-expression.cpp.output

Whitespace-only changes.

regression-tests/test-results/clang-18/pure2-print.cpp.output

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
sizeof(x) is 25
2+
(not a name)
3+
xyz

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/cppfront.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3108,6 +3108,16 @@ class cppfront
31083108
n.ops.front().op->type() == lexeme::MinusMinus
31093109
|| n.ops.front().op->type() == lexeme::PlusPlus
31103110
|| n.ops.front().op->type() == lexeme::Ampersand
3111+
|| (
3112+
std::ssize(n.ops) >= 2
3113+
&& n.ops.front().op->type() == lexeme::Dot
3114+
&&
3115+
(
3116+
n.ops[1].op->type() == lexeme::MinusMinus
3117+
|| n.ops[1].op->type() == lexeme::PlusPlus
3118+
|| n.ops[1].op->type() == lexeme::Ampersand
3119+
)
3120+
)
31113121
)
31123122
{
31133123
suppress_move_from_last_use = true;

0 commit comments

Comments
 (0)