Skip to content

[BUG] No implicit move for move this, explicit move doesn't parse #857

Closed
@JohelEGP

Description

@JohelEGP

Title: No implicit move for move this, explicit move doesn't parse.

Minimal reproducer (https://cpp2.godbolt.org/z/WhxKGfn83):

t: @basic_value type = {
  s: std::string = ();
  private get: (forward self) -> forward _ = self.s;
  operator*: (this) -> forward std::string = get(this);
  operator*: (move this) -> std::string = get(this); // `get(move this)` doesn't parse.
}
main: () = { }
Commands:
cppfront main.cpp2
clang++18 -std=c++23 -stdlib=libc++ -lc++abi -pedantic-errors -Wall -Wextra -Wconversion -Werror=unused-result -Werror=unused-value -Werror=unused-parameter -I . main.cpp

Expected result:

  [[nodiscard]] auto t::operator*() && -> std::string { return get(std::move(*this));  }

Actual result and error:

A copy.

  [[nodiscard]] auto t::operator*() && -> std::string { return get((*this));  }
Cpp2 lowered to Cpp1:
//=== Cpp2 type declarations ====================================================


#include "cpp2util.h"

#line 1 "/app/example.cpp2"
class t;
#line 2 "/app/example.cpp2"
  

//=== Cpp2 type definitions and function declarations ===========================

#line 1 "/app/example.cpp2"
class t {
#line 2 "/app/example.cpp2"
  private: std::string s {}; 
  private: [[nodiscard]] static auto get(auto&& self) -> auto&&;
  public: [[nodiscard]] auto operator*() const& -> std::string const&;
  public: [[nodiscard]] auto operator*() && -> std::string;
  public: t(t const& that);

public: auto operator=(t const& that) -> t& ;
public: t(t&& that) noexcept;
public: auto operator=(t&& that) noexcept -> t& ;
public: explicit t();

#line 6 "/app/example.cpp2"
};
auto main() -> int;

//=== Cpp2 function definitions =================================================

#line 1 "/app/example.cpp2"

#line 3 "/app/example.cpp2"
  [[nodiscard]] auto t::get(auto&& self) -> auto&& { return CPP2_FORWARD(self).s;  }
  [[nodiscard]] auto t::operator*() const& -> std::string const& { return get((*this));  }
  [[nodiscard]] auto t::operator*() && -> std::string { return get((*this));  }

  t::t(t const& that)
                                : s{ that.s }{}

auto t::operator=(t const& that) -> t& {
                                s = that.s;
                                return *this;}
t::t(t&& that) noexcept
                                : s{ std::move(that).s }{}
auto t::operator=(t&& that) noexcept -> t& {
                                s = std::move(that).s;
                                return *this;}
t::t(){}
#line 5 "/app/example.cpp2"
                                                     // `get(move this)` doesn't parse.

#line 7 "/app/example.cpp2"
auto main() -> int{}
Output:
Program returned: 0

See also:

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions