This is legal since C++23, see P2266R3. GCC 13+ and Clang 13+both implement it (both accept your code in C++23 mode), while MSVC doesn't yet.
This paper (among other things) extends the implicit move (that happens when returning a local variable that's either not a reference or an rvalue reference) to apply regardless of the return type, while it used to only work when returning non-references.