[v2,6/8] Rely on copy elision in scope-exit.h

Message ID 20231121152817.31859-7-tom@tromey.com
State New
Headers
Series [v2,1/8] Use C++17 [[fallthrough]] attribute |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed

Commit Message

Tom Tromey Nov. 21, 2023, 3:27 p.m. UTC
  gdbsupport/scope-exit.h has a couple of comments about being able to
rely on copy elision in C++17.  This patch makes the change.

Approved-By: Pedro Alves <pedro@palves.net>
---
 gdbsupport/scope-exit.h | 22 ++--------------------
 1 file changed, 2 insertions(+), 20 deletions(-)
  

Patch

diff --git a/gdbsupport/scope-exit.h b/gdbsupport/scope-exit.h
index cb8d9255869..8fa40b1ca8a 100644
--- a/gdbsupport/scope-exit.h
+++ b/gdbsupport/scope-exit.h
@@ -69,16 +69,7 @@  class scope_exit_base
       }
   }
 
-  /* This is needed for make_scope_exit because copy elision isn't
-     guaranteed until C++17.  An optimizing compiler will usually skip
-     calling this, but it must exist.  */
-  scope_exit_base (const scope_exit_base &other)
-    : m_released (other.m_released)
-  {
-    other.m_released = true;
-  }
-
-  void operator= (const scope_exit_base &) = delete;
+  DISABLE_COPY_AND_ASSIGN (scope_exit_base);
 
   /* If this is called, then the wrapped function will not be called
      on destruction.  */
@@ -132,16 +123,7 @@  class scope_exit : public scope_exit_base<scope_exit<EF>>
     rhs.release ();
   }
 
-  /* This is needed for make_scope_exit because copy elision isn't
-     guaranteed until C++17.  An optimizing compiler will usually skip
-     calling this, but it must exist.  */
-  scope_exit (const scope_exit &other)
-    : scope_exit_base<scope_exit<EF>> (other),
-      m_exit_function (other.m_exit_function)
-  {
-  }
-
-  void operator= (const scope_exit &) = delete;
+  DISABLE_COPY_AND_ASSIGN (scope_exit);
   void operator= (scope_exit &&) = delete;
 
 private: