Skip to content

Commit

Permalink
fix(cpp1): extend move supression to member access
Browse files Browse the repository at this point in the history
  • Loading branch information
JohelEGP committed Sep 14, 2023
1 parent ecd3726 commit d2939ac
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
4 changes: 4 additions & 0 deletions regression-tests/mixed-parameter-passing-with-forward.cpp2
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,20 @@ parameter_styles: (
)
= {
z: int = 12;
y: std::pair = (17, 29);

z++;
y.first--;
b += "plugh";

if std::rand()%2 {
z++;
y.first--;
copy_from(b); // definite last use
}
else {
copy_from(b&); // NB: better not move from this (why not?)
copy_from(y.second&); // Ditto
copy_from(d);
copy_from(z++);
copy_from(e);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
clang version 18.0.0 (https://git.uplinklabs.net/mirrors/llvm-project.git c0abd3814564a568dfc607c216e6407eaa314f46)
clang version 18.0.0 (https://github.com/llvm/llvm-project.git 3723ede3cf5324827f8fbbe7f484c2ee4d7a7204)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /home/johel/root/clang-main/bin
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ CPP2_REQUIRES (std::is_same_v<CPP2_TYPEOF(e), std::string>)
#line 8 "mixed-parameter-passing-with-forward.cpp2"
;

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


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

++z;
--y.first;
b += "plugh";

if (std::rand() % 2) {
++z;
--y.first;
copy_from(std::move(b));// definite last use
}
else {
copy_from(&b); // NB: better not move from this (why not?)
copy_from(&y.second); // Ditto
copy_from(std::move(d));
copy_from(++z);
copy_from(CPP2_FORWARD(e));
Expand Down
10 changes: 10 additions & 0 deletions source/cppfront.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3103,6 +3103,16 @@ class cppfront
n.ops.front().op->type() == lexeme::MinusMinus
|| n.ops.front().op->type() == lexeme::PlusPlus
|| n.ops.front().op->type() == lexeme::Ampersand
|| (
std::ssize(n.ops) >= 2
&& n.ops.front().op->type() == lexeme::Dot
&&
(
n.ops[1].op->type() == lexeme::MinusMinus
|| n.ops[1].op->type() == lexeme::PlusPlus
|| n.ops[1].op->type() == lexeme::Ampersand
)
)
)
{
suppress_move_from_last_use = true;
Expand Down

0 comments on commit d2939ac

Please sign in to comment.