0001-Do-not-define-basic_string_view-to_string.patch 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. From 5ac588997c3c2d032d5d5145d9245eb37354c23b Mon Sep 17 00:00:00 2001
  2. From: Tom Tromey <tromey@adacore.com>
  3. Date: Tue, 30 Jun 2020 07:53:03 -0600
  4. Subject: [PATCH] Do not define basic_string_view::to_string
  5. gdb's copy of basic_string_view includes a to_string method. However,
  6. according to cppreference, this is not a method on the real
  7. std::basic_string_view:
  8. https://en.cppreference.com/w/cpp/string/basic_string_view
  9. This difference matters because gdb_string_view.h will use the
  10. standard implementation when built with a C++17 or later. This caused
  11. PR build/26183.
  12. This patch fixes the problem by changing the method to be a standalone
  13. helper function, and then rewriting the uses. Tested by rebuilding
  14. with a version of GCC that defaults to C++17.
  15. (Note that the build still is not clean; and also I noticed that the
  16. libstdc++ string_view forbids the use of nullptr ... I wonder if gdb
  17. violates that.)
  18. gdb/ChangeLog
  19. 2020-06-30 Tom Tromey <tromey@adacore.com>
  20. PR build/26183:
  21. * ada-lang.c (ada_lookup_name_info::ada_lookup_name_info): Use
  22. gdb::to_string.
  23. gdbsupport/ChangeLog
  24. 2020-06-30 Tom Tromey <tromey@adacore.com>
  25. PR build/26183:
  26. * gdb_string_view.h (basic_string_view::to_string): Remove.
  27. (gdb::to_string): New function.
  28. Upstream: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=5ac588997c3c2d032d5d5145d9245eb37354c23b
  29. Bug report: https://sourceware.org/bugzilla/show_bug.cgi?id=26183
  30. Signed-off-by: Bernd Kuhls <bernd@kuhls.net>
  31. ---
  32. gdb/ChangeLog | 6 ++++++
  33. gdb/ada-lang.c | 8 ++++----
  34. gdbsupport/ChangeLog | 6 ++++++
  35. gdbsupport/gdb_string_view.h | 17 ++++++++++-------
  36. 4 files changed, 26 insertions(+), 11 deletions(-)
  37. diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
  38. index 9b0c2efbfe2..98508c168bc 100644
  39. --- a/gdb/ada-lang.c
  40. +++ b/gdb/ada-lang.c
  41. @@ -13553,10 +13553,10 @@ ada_lookup_name_info::ada_lookup_name_info (const lookup_name_info &lookup_name)
  42. {
  43. if (user_name.back () == '>')
  44. m_encoded_name
  45. - = user_name.substr (1, user_name.size () - 2).to_string ();
  46. + = gdb::to_string (user_name.substr (1, user_name.size () - 2));
  47. else
  48. m_encoded_name
  49. - = user_name.substr (1, user_name.size () - 1).to_string ();
  50. + = gdb::to_string (user_name.substr (1, user_name.size () - 1));
  51. m_encoded_p = true;
  52. m_verbatim_p = true;
  53. m_wild_match_p = false;
  54. @@ -13575,10 +13575,10 @@ ada_lookup_name_info::ada_lookup_name_info (const lookup_name_info &lookup_name)
  55. if (encoded != NULL)
  56. m_encoded_name = encoded;
  57. else
  58. - m_encoded_name = user_name.to_string ();
  59. + m_encoded_name = gdb::to_string (user_name);
  60. }
  61. else
  62. - m_encoded_name = user_name.to_string ();
  63. + m_encoded_name = gdb::to_string (user_name);
  64. /* Handle the 'package Standard' special case. See description
  65. of m_standard_p. */
  66. diff --git a/gdbsupport/gdb_string_view.h b/gdbsupport/gdb_string_view.h
  67. index c0ae7a8a2d9..65124e67e54 100644
  68. --- a/gdbsupport/gdb_string_view.h
  69. +++ b/gdbsupport/gdb_string_view.h
  70. @@ -245,13 +245,6 @@ namespace gdb {
  71. return { this->_M_str, this->_M_len };
  72. }
  73. - template<typename _Allocator = std::allocator<_CharT>>
  74. - std::basic_string<_CharT, _Traits, _Allocator>
  75. - to_string(const _Allocator& __alloc = _Allocator()) const
  76. - {
  77. - return { this->_M_str, this->_M_len, __alloc };
  78. - }
  79. -
  80. size_type
  81. copy(_CharT* __str, size_type __n, size_type __pos = 0) const
  82. {
  83. @@ -560,4 +553,14 @@ namespace gdb {
  84. #endif // __cplusplus < 201703L
  85. +namespace gdb {
  86. +
  87. +static inline std::string
  88. +to_string(const gdb::string_view &view)
  89. +{
  90. + return { view.data (), view.size () };
  91. +}
  92. +
  93. +}
  94. +
  95. #endif /* COMMON_GDB_STRING_VIEW_H */
  96. --
  97. 2.39.3