Skip to content

[BUG] Suspicious cpp1 std::move of returning expression #313

Closed
@realgdman

Description

@realgdman

Describe the bug
Hello, first, let me thank you all for great work.

I was learning language from the test cases, and something caught my eye in this line


I'm not C++ expert but I believe std::move(x) >> 1 doesn't make much sense in cpp1. It compiles, but I think move is lost to nowhere. (May be I am wrong and x is still marked as to be moved? But I think not)

To Reproduce
I have created this test:

dup: (a:_) -> _ = {
  x := a;
  return x + x;
}

inc: (a:_) -> _ = {
  x := a;
  return x + 1;
}

main: () -> int = {
  obj := 42;
  std::cout << dup(obj) << '\n';
  std::cout << inc(obj);
}

which generates following cpp1:

[[nodiscard]] auto dup(auto const& a) -> auto{
  auto x {a}; 
  return x + std::move(x); 
}

[[nodiscard]] auto inc(auto const& a) -> auto{
  auto x {a}; 
  return std::move(x) + 1; 
}

I believe both of those cases loses information about move.

Additional context
Example uses int, but I have checked with custom type (with operator+) and it behaves the same.
Also its the same for other operators like *, >> etc.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions