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-22  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.
This commit is contained in:
Yao Qi 2017-03-22 12:35:31 +00:00
parent 9d736fbf01
commit ffdbe8642e
5 changed files with 27 additions and 0 deletions

View File

@ -1,3 +1,11 @@
2017-03-22 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.
2017-03-22 Jonah Graham <jonah@kichwacoders.com>
PR gdb/19637

View File

@ -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. */

View File

@ -12952,6 +12952,7 @@ thumb2_record_decode_insn_handler (insn_decode_record *thumb2_insn_r)
return -1;
}
namespace {
/* Abstract memory reader. */
class abstract_memory_reader
@ -12977,6 +12978,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. */

View File

@ -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. */

View File

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