diff --git a/include/libtorrent/config.hpp b/include/libtorrent/config.hpp index dd1157367eb..c354f29e7b5 100644 --- a/include/libtorrent/config.hpp +++ b/include/libtorrent/config.hpp @@ -616,6 +616,12 @@ POSSIBILITY OF SUCH DAMAGE. #define __has_builtin(x) 0 // for non-clang compilers #endif +#if __cplusplus >= 202002L +#define TORRENT_RVO(x) x +#else +#define TORRENT_RVO(x) std::move(x) +#endif + #if (TORRENT_HAS_SSE && defined __GNUC__) # define TORRENT_HAS_BUILTIN_CLZ 1 #elif (TORRENT_HAS_ARM && defined __GNUC__ && !defined __clang__) diff --git a/src/alert.cpp b/src/alert.cpp index a848899ecb2..e0853ea9b3a 100644 --- a/src/alert.cpp +++ b/src/alert.cpp @@ -2579,7 +2579,7 @@ namespace { for (int i = 0; i < m_v6_num_peers; i++) peers.push_back(aux::read_v6_endpoint(v6_ptr)); - return std::move(peers); + return TORRENT_RVO(peers); } dht_direct_response_alert::dht_direct_response_alert( @@ -2819,7 +2819,7 @@ namespace { nodes.emplace_back(ih, aux::read_v6_endpoint(v6_ptr)); } - return std::move(nodes); + return TORRENT_RVO(nodes); } } @@ -2931,7 +2931,7 @@ namespace { char const* ptr = m_alloc.get().ptr(m_samples_idx); std::memcpy(samples.data(), ptr, samples.size() * 20); - return std::move(samples); + return TORRENT_RVO(samples); } int dht_sample_infohashes_alert::num_nodes() const diff --git a/src/session_stats.cpp b/src/session_stats.cpp index 6bbe196b3a4..d31125b2bac 100644 --- a/src/session_stats.cpp +++ b/src/session_stats.cpp @@ -584,7 +584,7 @@ namespace { stats[i].type = metrics[i].value_index >= counters::num_stats_counters ? metric_type_t::gauge : metric_type_t::counter; } - return std::move(stats); + return TORRENT_RVO(stats); } int find_metric_idx(string_view name) diff --git a/src/torrent_handle.cpp b/src/torrent_handle.cpp index 6f7415128f8..c255e7a7282 100644 --- a/src/torrent_handle.cpp +++ b/src/torrent_handle.cpp @@ -484,7 +484,7 @@ namespace libtorrent { { aux::vector ret; sync_call(&torrent::file_progress, std::ref(ret), flags); - return std::move(ret); + return TORRENT_RVO(ret); } void torrent_handle::post_file_progress(file_progress_flags_t const flags) const @@ -542,7 +542,7 @@ namespace libtorrent { aux::vector ret; auto retp = &ret; sync_call(&torrent::piece_priorities, retp); - return std::move(ret); + return TORRENT_RVO(ret); } #if TORRENT_ABI_VERSION == 1 @@ -598,7 +598,7 @@ namespace libtorrent { aux::vector ret; auto retp = &ret; sync_call(&torrent::file_priorities, retp); - return std::move(ret); + return TORRENT_RVO(ret); } #if TORRENT_ABI_VERSION == 1