[v2,04/21] libcc1: delete copy constructor and assignment operators

Message ID 20210428010119.806184-5-tom@tromey.com
State New
Headers show
Series
  • C++11-based improvements for libcc1
Related show

Commit Message

Tom Tromey April 28, 2021, 1:01 a.m.
Change libcc1 to use "= delete" for the copy constructor and
assignment operator, rather than the old approach of private methods
that are nowhere defined.

libcc1/ChangeLog
2021-04-27  Tom Tromey  <tom@tromey.com>

	* rpc.hh (argument_wrapper): Use delete for copy constructor.
	* connection.hh (class connection): Use delete for copy
	constructor.
	* callbacks.hh (class callbacks): Use delete for copy constructor.
---
 libcc1/ChangeLog     |  7 +++++++
 libcc1/callbacks.hh  |  7 +++----
 libcc1/connection.hh |  7 +++----
 libcc1/rpc.hh        | 42 ++++++++++++++++++------------------------
 4 files changed, 31 insertions(+), 32 deletions(-)

-- 
2.26.2

Comments

Martin Sebor via Gcc-patches April 28, 2021, 3:55 p.m. | #1
On 4/27/2021 7:01 PM, Tom Tromey wrote:
> Change libcc1 to use "= delete" for the copy constructor and

> assignment operator, rather than the old approach of private methods

> that are nowhere defined.

>

> libcc1/ChangeLog

> 2021-04-27  Tom Tromey  <tom@tromey.com>

>

> 	* rpc.hh (argument_wrapper): Use delete for copy constructor.

> 	* connection.hh (class connection): Use delete for copy

> 	constructor.

> 	* callbacks.hh (class callbacks): Use delete for copy constructor.


OK

jeff

Patch

diff --git a/libcc1/callbacks.hh b/libcc1/callbacks.hh
index b1f3e98d917b..dc470c62c48d 100644
--- a/libcc1/callbacks.hh
+++ b/libcc1/callbacks.hh
@@ -42,6 +42,9 @@  namespace cc1_plugin
     callbacks ();
     ~callbacks ();
 
+    callbacks (const callbacks &) = delete;
+    callbacks &operator= (const callbacks &) = delete;
+
     // Add a callback named NAME.  FUNC is the function to call when
     // this method is invoked.
     void add_callback (const char *name, callback_ftype *func);
@@ -52,10 +55,6 @@  namespace cc1_plugin
 
   private:
 
-    // Declared but not defined to avoid use.
-    callbacks (const callbacks &);
-    callbacks &operator= (const callbacks &);
-
     // The mapping.
     htab_t m_registry;
   };
diff --git a/libcc1/connection.hh b/libcc1/connection.hh
index a0e99bdbd98f..15ad1716a29e 100644
--- a/libcc1/connection.hh
+++ b/libcc1/connection.hh
@@ -48,6 +48,9 @@  namespace cc1_plugin
 
     virtual ~connection () = default;
 
+    connection (const connection &) = delete;
+    connection &operator= (const connection &) = delete;
+
     // Send a single character.  This is used to introduce various
     // higher-level protocol elements.
     status send (char c);
@@ -95,10 +98,6 @@  namespace cc1_plugin
 
   private:
 
-    // Declared but not defined, to prevent use.
-    connection (const connection &);
-    connection &operator= (const connection &);
-
     // Helper function for the wait_* methods.
     status do_wait (bool);
 
diff --git a/libcc1/rpc.hh b/libcc1/rpc.hh
index a8e33577ea18..429aeb3c1278 100644
--- a/libcc1/rpc.hh
+++ b/libcc1/rpc.hh
@@ -39,6 +39,9 @@  namespace cc1_plugin
     argument_wrapper () { }
     ~argument_wrapper () { }
 
+    argument_wrapper (const argument_wrapper &) = delete;
+    argument_wrapper &operator= (const argument_wrapper &) = delete;
+
     operator T () const { return m_object; }
 
     status unmarshall (connection *conn)
@@ -49,10 +52,6 @@  namespace cc1_plugin
   private:
 
     T m_object;
-
-    // No copying or assignment allowed.
-    argument_wrapper (const argument_wrapper &);
-    argument_wrapper &operator= (const argument_wrapper &);
   };
 
   // Specialization for any kind of pointer.  This is declared but not
@@ -72,6 +71,9 @@  namespace cc1_plugin
       delete[] m_object;
     }
 
+    argument_wrapper (const argument_wrapper &) = delete;
+    argument_wrapper &operator= (const argument_wrapper &) = delete;
+
     operator const char * () const
     {
       return m_object;
@@ -85,10 +87,6 @@  namespace cc1_plugin
   private:
 
     char *m_object;
-
-    // No copying or assignment allowed.
-    argument_wrapper (const argument_wrapper &);
-    argument_wrapper &operator= (const argument_wrapper &);
   };
 
   // Specialization for gcc_type_array.
@@ -106,6 +104,9 @@  namespace cc1_plugin
       delete m_object;
     }
 
+    argument_wrapper (const argument_wrapper &) = delete;
+    argument_wrapper &operator= (const argument_wrapper &) = delete;
+
     operator const gcc_type_array * () const
     {
       return m_object;
@@ -119,10 +120,6 @@  namespace cc1_plugin
   private:
 
     gcc_type_array *m_object;
-
-    // No copying or assignment allowed.
-    argument_wrapper (const argument_wrapper &);
-    argument_wrapper &operator= (const argument_wrapper &);
   };
 
 #ifdef GCC_CP_INTERFACE_H
@@ -144,6 +141,9 @@  namespace cc1_plugin
       delete m_object;
     }
 
+    argument_wrapper (const argument_wrapper &) = delete;
+    argument_wrapper &operator= (const argument_wrapper &) = delete;
+
     operator const gcc_vbase_array * () const
     {
       return m_object;
@@ -157,10 +157,6 @@  namespace cc1_plugin
   private:
 
     gcc_vbase_array *m_object;
-
-    // No copying or assignment allowed.
-    argument_wrapper (const argument_wrapper &);
-    argument_wrapper &operator= (const argument_wrapper &);
   };
 
   // Specialization for gcc_cp_template_args.
@@ -181,6 +177,9 @@  namespace cc1_plugin
       delete m_object;
     }
 
+    argument_wrapper (const argument_wrapper &) = delete;
+    argument_wrapper &operator= (const argument_wrapper &) = delete;
+
     operator const gcc_cp_template_args * () const
     {
       return m_object;
@@ -194,10 +193,6 @@  namespace cc1_plugin
   private:
 
     gcc_cp_template_args *m_object;
-
-    // No copying or assignment allowed.
-    argument_wrapper (const argument_wrapper &);
-    argument_wrapper &operator= (const argument_wrapper &);
   };
 
   // Specialization for gcc_cp_function_args.
@@ -217,6 +212,9 @@  namespace cc1_plugin
       delete m_object;
     }
 
+    argument_wrapper (const argument_wrapper &) = delete;
+    argument_wrapper &operator= (const argument_wrapper &) = delete;
+
     operator const gcc_cp_function_args * () const
     {
       return m_object;
@@ -230,10 +228,6 @@  namespace cc1_plugin
   private:
 
     gcc_cp_function_args *m_object;
-
-    // No copying or assignment allowed.
-    argument_wrapper (const argument_wrapper &);
-    argument_wrapper &operator= (const argument_wrapper &);
   };
 #endif /* GCC_CP_INTERFACE_H */