This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH] Add DISABLE_COPY_AND_ASSIGN
- From: Yao Qi <qiyaoltc at gmail dot com>
- To: gdb-patches at sourceware dot org
- Date: Tue, 18 Jul 2017 14:48:06 +0100
- Subject: [PATCH] Add DISABLE_COPY_AND_ASSIGN
- Authentication-results: sourceware.org; auth=none
We have many classes that copy cotr and assignment operator are deleted,
so this patch adds a macro to do this, and replace these existing
mechanical code with macro DISABLE_COPY_AND_ASSIGN.
gdb:
2017-07-18 Yao Qi <yao.qi@linaro.org>
* common/common-defs.h (DISABLE_COPY_AND_ASSIGN): New macro.
* annotate.h (struct annotate_arg_emitter): Use
DISABLE_COPY_AND_ASSIGN.
* common/refcounted-object.h (refcounted_object): Likewise.
* completer.h (struct completion_result): Likewise.
* dwarf2read.c (struct dwarf2_per_objfile): Likewise.
* filename-seen-cache.h (filename_seen_cache): Likewise.
* gdbcore.h (thread_section_name): Likewise.
* gdb_regex.h (compiled_regex): Likewise.
* gdbthread.h (scoped_restore_current_thread): Likewise.
* inferior.h (scoped_restore_current_inferior): Likewise.
* jit.c (jit_reader): Likewise.
* linespec.h (struct linespec_result): Likewise.
* mi/mi-parse.h (struct mi_parse): Likewise.
* nat/fork-inferior.c (execv_argv): Likewise.
* progspace.h (scoped_restore_current_program_space): Likewise.
* python/python-internal.h (class gdbpy_enter): Likewise.
* regcache.h (regcache): Likewise.
* target-descriptions.c (struct tdesc_reg): Likewise.
(struct tdesc_type): Likewise.
(struct tdesc_feature): Likewise.
* ui-out.h (public:): Likewise.
---
gdb/annotate.h | 3 +--
gdb/common/common-defs.h | 4 ++++
gdb/common/refcounted-object.h | 6 +++---
gdb/completer.h | 8 ++------
gdb/dwarf2read.c | 4 +---
gdb/filename-seen-cache.h | 4 +---
gdb/gdb_regex.h | 4 +---
gdb/gdbcore.h | 4 +---
gdb/gdbthread.h | 6 +-----
gdb/inferior.h | 6 +-----
gdb/jit.c | 3 +--
gdb/linespec.h | 3 +--
gdb/mi/mi-parse.h | 3 +--
gdb/nat/fork-inferior.c | 4 +---
gdb/progspace.h | 6 +-----
gdb/python/python-internal.h | 3 +--
gdb/regcache.h | 3 +--
gdb/target-descriptions.c | 13 ++++---------
gdb/ui-out.h | 4 +---
19 files changed, 28 insertions(+), 63 deletions(-)
diff --git a/gdb/annotate.h b/gdb/annotate.h
index 7161689..8a9a641 100644
--- a/gdb/annotate.h
+++ b/gdb/annotate.h
@@ -81,8 +81,7 @@ struct annotate_arg_emitter
annotate_arg_emitter () { annotate_arg_begin (); }
~annotate_arg_emitter () { annotate_arg_end (); }
- annotate_arg_emitter (const annotate_arg_emitter &) = delete;
- annotate_arg_emitter &operator= (const annotate_arg_emitter &) = delete;
+ DISABLE_COPY_AND_ASSIGN (annotate_arg_emitter);
};
extern void annotate_source (char *, int, int, int,
diff --git a/gdb/common/common-defs.h b/gdb/common/common-defs.h
index 439bce6..ccb0fcb 100644
--- a/gdb/common/common-defs.h
+++ b/gdb/common/common-defs.h
@@ -91,4 +91,8 @@
/* Pull in gdb::unique_xmalloc_ptr. */
#include "common/gdb_unique_ptr.h"
+#define DISABLE_COPY_AND_ASSIGN(TYPE) \
+ TYPE (const TYPE&) = delete; \
+ void operator= (const TYPE &) = delete;
+
#endif /* COMMON_DEFS_H */
diff --git a/gdb/common/refcounted-object.h b/gdb/common/refcounted-object.h
index 9d0ac10..a7a9cbd 100644
--- a/gdb/common/refcounted-object.h
+++ b/gdb/common/refcounted-object.h
@@ -19,6 +19,8 @@
#ifndef REFCOUNTED_OBJECT_H
#define REFCOUNTED_OBJECT_H
+#include "common-defs.h"
+
/* Base class of intrusively reference-countable objects.
Incrementing and decrementing the reference count is an external
responsibility. */
@@ -45,9 +47,7 @@ public:
int refcount () const { return m_refcount; }
private:
- /* Disable copy. */
- refcounted_object (const refcounted_object &) = delete;
- refcounted_object &operator=(const refcounted_object &) = delete;
+ DISABLE_COPY_AND_ASSIGN (refcounted_object);
/* The reference count. */
int m_refcount = 0;
diff --git a/gdb/completer.h b/gdb/completer.h
index f68c6dc..82a994c 100644
--- a/gdb/completer.h
+++ b/gdb/completer.h
@@ -85,9 +85,7 @@ struct completion_result
/* Destroy a result. */
~completion_result ();
- /* Disable copying, since we don't need it. */
- completion_result (const completion_result &rhs) = delete;
- void operator= (const completion_result &rhs) = delete;
+ DISABLE_COPY_AND_ASSIGN (completion_result);
/* Move a result. */
completion_result (completion_result &&rhs);
@@ -146,9 +144,7 @@ public:
completion_tracker ();
~completion_tracker ();
- /* Disable copy. */
- completion_tracker (const completion_tracker &rhs) = delete;
- void operator= (const completion_tracker &rhs) = delete;
+ DISABLE_COPY_AND_ASSIGN (completion_tracker);
/* Add the completion NAME to the list of generated completions if
it is not there already. If too many completions were already
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index bb69f44..1c464f8 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -232,9 +232,7 @@ struct dwarf2_per_objfile
~dwarf2_per_objfile ();
- /* Disable copy. */
- dwarf2_per_objfile (const dwarf2_per_objfile &) = delete;
- void operator= (const dwarf2_per_objfile &) = delete;
+ DISABLE_COPY_AND_ASSIGN (dwarf2_per_objfile);
/* Free all cached compilation units. */
void free_cached_comp_units ();
diff --git a/gdb/filename-seen-cache.h b/gdb/filename-seen-cache.h
index dd9cf7a..549effd 100644
--- a/gdb/filename-seen-cache.h
+++ b/gdb/filename-seen-cache.h
@@ -28,9 +28,7 @@ public:
filename_seen_cache ();
~filename_seen_cache ();
- /* Disable copy. */
- filename_seen_cache (const filename_seen_cache &) = delete;
- void operator= (const filename_seen_cache &) = delete;
+ DISABLE_COPY_AND_ASSIGN (filename_seen_cache);
/* Empty the cache, but do not delete it. */
void clear ();
diff --git a/gdb/gdb_regex.h b/gdb/gdb_regex.h
index f62f81d..1ef948e 100644
--- a/gdb/gdb_regex.h
+++ b/gdb/gdb_regex.h
@@ -43,9 +43,7 @@ public:
~compiled_regex ();
- /* Disable copy. */
- compiled_regex (const compiled_regex&) = delete;
- void operator= (const compiled_regex&) = delete;
+ DISABLE_COPY_AND_ASSIGN (compiled_regex);
/* Wrapper around ::regexec. */
int exec (const char *string,
diff --git a/gdb/gdbcore.h b/gdb/gdbcore.h
index 87f3dcd..55107e7 100644
--- a/gdb/gdbcore.h
+++ b/gdb/gdbcore.h
@@ -258,9 +258,7 @@ public:
const char *c_str () const
{ return m_section_name; }
- /* Disable copy. */
- thread_section_name (const thread_section_name &) = delete;
- void operator= (const thread_section_name &) = delete;
+ DISABLE_COPY_AND_ASSIGN (thread_section_name);
private:
/* Either a pointer into M_STORAGE, or a pointer to the name passed
diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h
index 046bf95..fe7acc2 100644
--- a/gdb/gdbthread.h
+++ b/gdb/gdbthread.h
@@ -597,11 +597,7 @@ public:
scoped_restore_current_thread ();
~scoped_restore_current_thread ();
- /* Disable copy. */
- scoped_restore_current_thread
- (const scoped_restore_current_thread &) = delete;
- void operator=
- (const scoped_restore_current_thread &) = delete;
+ DISABLE_COPY_AND_ASSIGN (scoped_restore_current_thread);
private:
thread_info *m_thread;
diff --git a/gdb/inferior.h b/gdb/inferior.h
index 8ada4f8..38b5e2c 100644
--- a/gdb/inferior.h
+++ b/gdb/inferior.h
@@ -532,11 +532,7 @@ public:
~scoped_restore_current_inferior ()
{ set_current_inferior (m_saved_inf); }
- /* Disable copy. */
- scoped_restore_current_inferior
- (const scoped_restore_current_inferior &) = delete;
- void operator=
- (const scoped_restore_current_inferior &) = delete;
+ DISABLE_COPY_AND_ASSIGN (scoped_restore_current_inferior);
private:
inferior *m_saved_inf;
diff --git a/gdb/jit.c b/gdb/jit.c
index ddf1005..113f720 100644
--- a/gdb/jit.c
+++ b/gdb/jit.c
@@ -163,8 +163,7 @@ struct jit_reader
functions->destroy (functions);
}
- jit_reader (const jit_reader &) = delete;
- jit_reader &operator= (const jit_reader &) = delete;
+ DISABLE_COPY_AND_ASSIGN (jit_reader);
struct gdb_reader_funcs *functions;
gdb_dlhandle_up handle;
diff --git a/gdb/linespec.h b/gdb/linespec.h
index 27d237a..8ea32c4 100644
--- a/gdb/linespec.h
+++ b/gdb/linespec.h
@@ -68,8 +68,7 @@ struct linespec_result
~linespec_result ();
- linespec_result (const linespec_result &) = delete;
- linespec_result &operator= (const linespec_result &) = delete;
+ DISABLE_COPY_AND_ASSIGN (linespec_result);
/* If non-zero, the linespec should be displayed to the user. This
is used by "unusual" linespecs where the ordinary `info break'
diff --git a/gdb/mi/mi-parse.h b/gdb/mi/mi-parse.h
index a4903df..2ac7681 100644
--- a/gdb/mi/mi-parse.h
+++ b/gdb/mi/mi-parse.h
@@ -44,8 +44,7 @@ struct mi_parse
mi_parse ();
~mi_parse ();
- mi_parse (const mi_parse &) = delete;
- mi_parse &operator= (const mi_parse &) = delete;
+ DISABLE_COPY_AND_ASSIGN (mi_parse);
enum mi_command_type op;
char *command;
diff --git a/gdb/nat/fork-inferior.c b/gdb/nat/fork-inferior.c
index 0913409..b9eab7f 100644
--- a/gdb/nat/fork-inferior.c
+++ b/gdb/nat/fork-inferior.c
@@ -56,9 +56,7 @@ public:
}
private:
- /* Disable copying. */
- execv_argv (const execv_argv &) = delete;
- void operator= (const execv_argv &) = delete;
+ DISABLE_COPY_AND_ASSIGN (execv_argv);
/* Helper methods for constructing the argument vector. */
diff --git a/gdb/progspace.h b/gdb/progspace.h
index ec1f482..f679fe3 100644
--- a/gdb/progspace.h
+++ b/gdb/progspace.h
@@ -273,11 +273,7 @@ public:
~scoped_restore_current_program_space ()
{ set_current_program_space (m_saved_pspace); }
- /* Disable copy. */
- scoped_restore_current_program_space
- (const scoped_restore_current_program_space &) = delete;
- void operator=
- (const scoped_restore_current_program_space &) = delete;
+ DISABLE_COPY_AND_ASSIGN (scoped_restore_current_program_space);
private:
program_space *m_saved_pspace;
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index ebb83f0..0ad1ffd 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -650,8 +650,7 @@ class gdbpy_enter
~gdbpy_enter ();
- gdbpy_enter (const gdbpy_enter &) = delete;
- gdbpy_enter &operator= (const gdbpy_enter &) = delete;
+ DISABLE_COPY_AND_ASSIGN (gdbpy_enter);
private:
diff --git a/gdb/regcache.h b/gdb/regcache.h
index aa64a00..eb0454a 100644
--- a/gdb/regcache.h
+++ b/gdb/regcache.h
@@ -255,8 +255,7 @@ public:
/* Create a readonly regcache from a non-readonly regcache. */
regcache (readonly_t, const regcache &src);
- regcache (const regcache &) = delete;
- void operator= (const regcache &) = delete;
+ DISABLE_COPY_AND_ASSIGN (regcache);
/* class regcache is only extended in unit test, so only mark it
virtual when selftest is enabled. */
diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c
index 0b5b46f..f7e432d 100644
--- a/gdb/target-descriptions.c
+++ b/gdb/target-descriptions.c
@@ -69,9 +69,7 @@ typedef struct tdesc_reg
xfree (group);
}
- /* Disable copying. */
- tdesc_reg (const tdesc_reg &) = delete;
- tdesc_reg &operator= (const tdesc_reg &) = delete;
+ DISABLE_COPY_AND_ASSIGN (tdesc_reg);
/* The name of this register. In standard features, it may be
recognized by the architecture support code, or it may be purely
@@ -185,9 +183,8 @@ typedef struct tdesc_type
}
xfree ((char *) name);
}
- /* Disable copying. */
- tdesc_type (const tdesc_type &) = delete;
- tdesc_type &operator= (const tdesc_type &) = delete;
+
+ DISABLE_COPY_AND_ASSIGN (tdesc_type);
/* The name of this type. If this type is a built-in type, this is
a pointer to a constant string. Otherwise, it's a
@@ -243,9 +240,7 @@ typedef struct tdesc_feature
xfree (name);
}
- /* Disable copying. */
- tdesc_feature (const tdesc_feature &) = delete;
- tdesc_feature &operator= (const tdesc_feature &) = delete;
+ DISABLE_COPY_AND_ASSIGN (tdesc_feature);
/* The name of this feature. It may be recognized by the architecture
support code. */
diff --git a/gdb/ui-out.h b/gdb/ui-out.h
index 9278cab..7bdb670 100644
--- a/gdb/ui-out.h
+++ b/gdb/ui-out.h
@@ -208,9 +208,7 @@ public:
m_uiout->end (Type);
}
- ui_out_emit_type (const ui_out_emit_type<Type> &) = delete;
- ui_out_emit_type<Type> &operator= (const ui_out_emit_type<Type> &)
- = delete;
+ DISABLE_COPY_AND_ASSIGN (ui_out_emit_type<Type>);
private:
--
1.9.1