diff mbox series

PR libstdc++/85671 allow copy elision in path concatenation

Message ID 20180507172617.GA440@redhat.com
State New
Headers show
Series PR libstdc++/85671 allow copy elision in path concatenation | expand

Commit Message

Jonathan Wakely May 7, 2018, 5:26 p.m. UTC
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.

Tested powerpc64le-linux, committed to trunk.
commit e6b809f624733aae6e03fca3f720c9cb4037e111
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Mon May 7 13:59:17 2018 +0100

    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.
diff mbox series

Patch

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<typename _CharT, typename _Traits>
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<typename _CharT, typename _Traits>