Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cpp1): extend move supression to member access
Browse files Browse the repository at this point in the history
JohelEGP committed Sep 22, 2023

Verified

This commit was signed with the committer’s verified signature. The key has expired.
addaleax Anna Henningsen
1 parent efd185f commit cbcd5a0
Showing 8 changed files with 26 additions and 1 deletion.
4 changes: 4 additions & 0 deletions regression-tests/mixed-parameter-passing-with-forward.cpp2
Original file line number Diff line number Diff line change
@@ -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);
4 changes: 4 additions & 0 deletions regression-tests/test-results/clang-18/clang-version.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
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
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sizeof(x) is 25
(not a name)
xyz
Original file line number Diff line number Diff line change
@@ -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;


@@ -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));
10 changes: 10 additions & 0 deletions source/cppfront.cpp
Original file line number Diff line number Diff line change
@@ -3108,6 +3108,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;

0 comments on commit cbcd5a0

Please sign in to comment.