Do not define basic_string_view::to_string

gdb's copy of basic_string_view includes a to_string method.  However,
according to cppreference, this is not a method on the real
std::basic_string_view:

https://en.cppreference.com/w/cpp/string/basic_string_view

This difference matters because gdb_string_view.h will use the
standard implementation when built with a C++17 or later.  This caused
PR build/26183.

This patch fixes the problem by changing the method to be a standalone
helper function, and then rewriting the uses.  Tested by rebuilding
with a version of GCC that defaults to C++17.

(Note that the build still is not clean; and also I noticed that the
libstdc++ string_view forbids the use of nullptr ... I wonder if gdb
violates that.)

gdb/ChangeLog
2020-06-30  Tom Tromey  <tromey@adacore.com>

	PR build/26183:
	* ada-lang.c (ada_lookup_name_info::ada_lookup_name_info): Use
	gdb::to_string.

gdbsupport/ChangeLog
2020-06-30  Tom Tromey  <tromey@adacore.com>

	PR build/26183:
	* gdb_string_view.h (basic_string_view::to_string): Remove.
	(gdb::to_string): New function.
This commit is contained in:
Tom Tromey
2020-06-30 07:53:03 -06:00
parent 5568cc9ee8
commit 5ac588997c
4 changed files with 26 additions and 11 deletions

View File

@@ -245,13 +245,6 @@ namespace gdb {
return { this->_M_str, this->_M_len };
}
template<typename _Allocator = std::allocator<_CharT>>
std::basic_string<_CharT, _Traits, _Allocator>
to_string(const _Allocator& __alloc = _Allocator()) const
{
return { this->_M_str, this->_M_len, __alloc };
}
size_type
copy(_CharT* __str, size_type __n, size_type __pos = 0) const
{
@@ -560,4 +553,14 @@ namespace gdb {
#endif // __cplusplus < 201703L
namespace gdb {
static inline std::string
to_string(const gdb::string_view &view)
{
return { view.data (), view.size () };
}
}
#endif /* COMMON_GDB_STRING_VIEW_H */