The decltype(auto) mechanism correctly holds the reference on the POSIX branch because you are returning a named lvalue (path). On the Windows branch, you are returning a prvalue (a temporary object), so the deduced type is the plain value type (std::filesystem::path), which is exactly the desired behavior.