PR libstdc++/85671 allow copy elision in path concatenation
authorJonathan Wakely <jwakely@redhat.com>
Mon, 7 May 2018 17:26:28 +0000 (18:26 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Mon, 7 May 2018 17:26:28 +0000 (18:26 +0100)
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
libstdc++-v3/include/bits/fs_path.h
libstdc++-v3/include/experimental/bits/fs_path.h

index 94f08c22a4f6d52fafe3a3ecacd81f010e75dfe4..cdbc44ecdf508f91dd998ceba268cb3ad87bfbfa 100644 (file)
@@ -1,3 +1,9 @@
+2018-05-07  Jonathan Wakely  <jwakely@redhat.com>
+
+       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
index 31c34d67c75fcf02e7e5907bdf0bda2b20a72258..6703e9167e4e2aa72b1ed10df03bebefdbe3541a 100644 (file)
@@ -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<typename _CharT, typename _Traits>
index 456452bb317d4379d1039b59da4df77de996046a..3b4011e64149647f5556f4335e789fb02e40d4a2 100644 (file)
@@ -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<typename _CharT, typename _Traits>