From a989f6378b1b08aa3145c7bd77477282ddc5e553 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Mon, 7 May 2018 18:26:28 +0100 Subject: [PATCH] PR libstdc++/85671 allow copy elision in path concatenation By performing the /= operation on a named local variable instead of a temporary the copy made for the return value can be elided. PR libstdc++/85671 * include/bits/fs_path.h (operator/): Permit copy elision. * include/experimental/bits/fs_path.h (operator/): Likewise. From-SVN: r260009 --- libstdc++-v3/ChangeLog | 6 ++++++ libstdc++-v3/include/bits/fs_path.h | 6 +++++- libstdc++-v3/include/experimental/bits/fs_path.h | 6 +++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 94f08c22a4f..cdbc44ecdf5 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,9 @@ +2018-05-07 Jonathan Wakely + + PR libstdc++/85671 + * include/bits/fs_path.h (operator/): Permit copy elision. + * include/experimental/bits/fs_path.h (operator/): Likewise. + 2018-05-07 Edward Smith-Rowland <3dw4rd@verizon.net> Moar PR libstdc++/80506 diff --git a/libstdc++-v3/include/bits/fs_path.h b/libstdc++-v3/include/bits/fs_path.h index 31c34d67c75..6703e9167e4 100644 --- a/libstdc++-v3/include/bits/fs_path.h +++ b/libstdc++-v3/include/bits/fs_path.h @@ -552,7 +552,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 /// Append one path to another inline path operator/(const path& __lhs, const path& __rhs) - { return path(__lhs) /= __rhs; } + { + path __result(__lhs); + __result /= __rhs; + return __result; + } /// Write a path to a stream template diff --git a/libstdc++-v3/include/experimental/bits/fs_path.h b/libstdc++-v3/include/experimental/bits/fs_path.h index 456452bb317..3b4011e6414 100644 --- a/libstdc++-v3/include/experimental/bits/fs_path.h +++ b/libstdc++-v3/include/experimental/bits/fs_path.h @@ -510,7 +510,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 /// Append one path to another inline path operator/(const path& __lhs, const path& __rhs) - { return path(__lhs) /= __rhs; } + { + path __result(__lhs); + __result /= __rhs; + return __result; + } /// Write a path to a stream template -- 2.30.2