This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Wrap locally used classes in anonymous namespace


Both aarch64-tdep.c and arm-tdep.c defines a class instruction_reader, which
violates ODR, but linker doesn't an emit error.  I fix this issue by wrapping
them by anonymous namespace, but I think it is better to apply this for all
locally used classes.

If it is a good idea to put locally used class into anonymous namespace, we
should document this rule into GDB coding convention, or even GCC coding
convention.  Note that anonymous namespace has been used in GCC but GCC
coding convention doesn't mention the it.

gdb:

2017-03-20  Yao Qi  <yao.qi@linaro.org>

	* aarch64-tdep.c: Wrap locally used classes in anonymous
	namespace.
	* arm-tdep.c: Likewise.
	* linespec.c: Likewise.
	* ui-out.c: Likewise.
---
 gdb/aarch64-tdep.c | 4 ++++
 gdb/arm-tdep.c     | 3 +++
 gdb/linespec.c     | 8 ++++++++
 gdb/ui-out.c       | 4 ++++
 4 files changed, 19 insertions(+)

diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
index 801c03d..b922174 100644
--- a/gdb/aarch64-tdep.c
+++ b/gdb/aarch64-tdep.c
@@ -196,6 +196,8 @@ show_aarch64_debug (struct ui_file *file, int from_tty,
   fprintf_filtered (file, _("AArch64 debugging is %s.\n"), value);
 }
 
+namespace {
+
 /* Abstract instruction reader.  */
 
 class abstract_instruction_reader
@@ -217,6 +219,8 @@ class instruction_reader : public abstract_instruction_reader
   }
 };
 
+} // namespace
+
 /* Analyze a prologue, looking for a recognizable stack frame
    and frame pointer.  Scan until we encounter a store that could
    clobber the stack frame unexpectedly, or an unknown instruction.  */
diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index 98d8e0e..b168f43 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -12951,6 +12951,7 @@ thumb2_record_decode_insn_handler (insn_decode_record *thumb2_insn_r)
   return -1;
 }
 
+namespace {
 /* Abstract memory reader.  */
 
 class abstract_memory_reader
@@ -12976,6 +12977,8 @@ class instruction_reader : public abstract_memory_reader
   }
 };
 
+} // namespace
+
 /* Extracts arm/thumb/thumb2 insn depending on the size, and returns 0 on success 
 and positive val on fauilure.  */
 
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 72bcd60..a3cb0cb 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -2793,6 +2793,8 @@ decode_objc (struct linespec_state *self, linespec_p ls, const char *arg)
   return values;
 }
 
+namespace {
+
 /* A function object that serves as symbol_found_callback_ftype
    callback for iterate_over_symbols.  This is used by
    lookup_prefix_sym to collect type symbols.  */
@@ -2859,6 +2861,8 @@ decode_compound_collector::operator () (symbol *sym)
   return true; /* Continue iterating.  */
 }
 
+} // namespace
+
 /* Return any symbols corresponding to CLASS_NAME in FILE_SYMTABS.  */
 
 static VEC (symbolp) *
@@ -3095,6 +3099,8 @@ find_method (struct linespec_state *self, VEC (symtab_ptr) *file_symtabs,
 
 
 
+namespace {
+
 /* This function object is a callback for iterate_over_symtabs, used
    when collecting all matching symtabs.  */
 
@@ -3148,6 +3154,8 @@ symtab_collector::operator () (struct symtab *symtab)
   return false;
 }
 
+} // namespace
+
 /* Given a file name, return a VEC of all matching symtabs.  If
    SEARCH_PSPACE is not NULL, the search is restricted to just that
    program space.  */
diff --git a/gdb/ui-out.c b/gdb/ui-out.c
index 42cffbe..9c27742 100644
--- a/gdb/ui-out.c
+++ b/gdb/ui-out.c
@@ -30,6 +30,8 @@
 #include <string>
 #include <memory>
 
+namespace {
+
 /* A header of a ui_out_table.  */
 
 class ui_out_hdr
@@ -91,6 +93,8 @@ class ui_out_hdr
   std::string m_header;
 };
 
+} // namespace
+
 /* A level of nesting (either a list or a tuple) in a ui_out output.  */
 
 class ui_out_level
-- 
1.9.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]