Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Expand Up @@ -30,7 +30,7 @@ CPP2_REQUIRES (std::is_convertible_v<CPP2_TYPEOF(e), std::add_const_t<std::strin
#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;

//=== Cpp2 function definitions =================================================
Expand All @@ -52,16 +52,20 @@ requires (std::is_convertible_v<CPP2_TYPEOF(e), std::add_const_t<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(cpp2::move(b));// definite last use
}
else {
copy_from(&b); // NB: better not move from this (why not?)
copy_from(&y.second); // Ditto
copy_from(cpp2::move(d));
copy_from(++z);
copy_from(CPP2_FORWARD(e));
Expand All @@ -77,6 +81,6 @@ requires (std::is_convertible_v<CPP2_TYPEOF(e), std::add_const_t<std::string>&>)

}

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

10 changes: 10 additions & 0 deletions source/to_cpp1.h
Original file line number Diff line number Diff line change
Expand Up @@ -3592,6 +3592,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