https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110162

            Bug ID: 110162
           Summary: redundant move in initialization
           Product: gcc
           Version: 13.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jincikang at gmail dot com
  Target Milestone: ---

$ cat main.cpp
```cpp
// main.cpp
#include <string>

class HttpMessage {
public:
    std::string* body() noexcept {
        return &body_;
    }

    const std::string* body() const noexcept {
        return &body_;
    }

    void set_body(std::string s) {
        body_ = std::move(s);
    }
private:
    std::string body_;
};

class HttpResponse : private HttpMessage {
public:
    using HttpMessage::body;
    using HttpMessage::set_body;
private:
};

class HttpRequest : private HttpMessage {
public:
    using HttpMessage::body;
    using HttpMessage::set_body;
};

int main() {
  [[maybe_unused]]auto post = [](const HttpRequest& request, HttpResponse*
response) {
    response->set_body(std::move(*request.body()));
  };
}
```
$ g++ -std=c++2a -Werror -Wall -Wextra main.cpp
Error: redundant move in initialization [-Werror=redundant-move]
   35 |     response->set_body(std::move(*request.body()));
      |                        ~~~~~~~~~^~~~~~~~~~~~~~~~~

# OK.
$ clang++ -std=c++2a -Werror -Wall -Wextra main.cpp
# Ok
$ g++-12 -std=c++2a -Werror -Wall -Wextra main.cpp

Reply via email to