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 <jwak...@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 --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>

Reply via email to