]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Do not define basic_string_view::to_string
authorTom Tromey <tromey@adacore.com>
Tue, 30 Jun 2020 13:53:03 +0000 (07:53 -0600)
committerTom Tromey <tromey@adacore.com>
Tue, 30 Jun 2020 13:53:03 +0000 (07:53 -0600)
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.

gdb/ChangeLog
gdb/ada-lang.c
gdbsupport/ChangeLog
gdbsupport/gdb_string_view.h

index fb1912c2d91973a6fa7567951daffe7452815a5d..ddd831e7311ce7d8473ca7aa66a44da8cefaa1bc 100644 (file)
@@ -1,3 +1,9 @@
+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.
+
 2020-06-29  Simon Marchi  <simon.marchi@efficios.com>
 
        * gdbarch.sh (displaced_step_copy_insn): Update doc.
index 9b0c2efbfe21a9f347d380cf7e4ed48fe59c62d5..98508c168bc127d2c22dde4c6cb326da4ce6dfa4 100644 (file)
@@ -13553,10 +13553,10 @@ ada_lookup_name_info::ada_lookup_name_info (const lookup_name_info &lookup_name)
     {
       if (user_name.back () == '>')
        m_encoded_name
-         = user_name.substr (1, user_name.size () - 2).to_string ();
+         = gdb::to_string (user_name.substr (1, user_name.size () - 2));
       else
        m_encoded_name
-         = user_name.substr (1, user_name.size () - 1).to_string ();
+         = gdb::to_string (user_name.substr (1, user_name.size () - 1));
       m_encoded_p = true;
       m_verbatim_p = true;
       m_wild_match_p = false;
@@ -13575,10 +13575,10 @@ ada_lookup_name_info::ada_lookup_name_info (const lookup_name_info &lookup_name)
          if (encoded != NULL)
            m_encoded_name = encoded;
          else
-           m_encoded_name = user_name.to_string ();
+           m_encoded_name = gdb::to_string (user_name);
        }
       else
-       m_encoded_name = user_name.to_string ();
+       m_encoded_name = gdb::to_string (user_name);
 
       /* Handle the 'package Standard' special case.  See description
         of m_standard_p.  */
index 4db482b151961de04f69fd2d2cd7cb1103d79ff8..e1b040d5827b79d8572cf93345c5633caf63442d 100644 (file)
@@ -1,3 +1,9 @@
+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.
+
 2020-06-27  Simon Marchi  <simon.marchi@efficios.com>
 
        * tdesc.h (class print_xml_feature) <add_line>: Add
index c0ae7a8a2d9d4245bd3b72415aa3d20968f3adc4..65124e67e5428ad517c4b8337f99c79bd7b8d5a5 100644 (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 */