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

            Bug ID: 121433
           Summary: -Wredundant-move false positive
           Product: gcc
           Version: 15.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jylefort at gmail dot com
  Target Milestone: ---

```
#include <optional>
#include <string>

std::optional<std::string> foo() {
  std::string r;
  return std::move(r);
}
```

Compiled as follows:

```
$ g++ -std=c++23 -Wall -Wextra -c test.cxx 
test.cxx: In function ‘std::optional<std::__cxx11::basic_string<char> > foo()’:
test.cxx:6:19: warning: redundant move in return statement [-Wredundant-move]
    6 |   return std::move(r);
      |          ~~~~~~~~~^~~
test.cxx:6:19: note: remove ‘std::move’ call
```

In my understanding, this is a false positive: NRVO can't kick in as the type
of `r` (`std::string`) and the function return type
(`std::optional<std::string>`) differ.

Reply via email to