From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from rock.gnat.com (rock.gnat.com [IPv6:2620:20:4000:0:a9e:1ff:fe9b:1d1]) by sourceware.org (Postfix) with ESMTP id CEE483870867 for ; Mon, 29 Jun 2020 19:08:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org CEE483870867 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey@adacore.com Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 8C92311675E; Mon, 29 Jun 2020 15:08:12 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at gnat.com Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id vj+w3B8q0WT7; Mon, 29 Jun 2020 15:08:12 -0400 (EDT) Received: from murgatroyd.Home (174-16-104-48.hlrn.qwest.net [174.16.104.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPSA id 48AF01160A1; Mon, 29 Jun 2020 15:08:12 -0400 (EDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Do not define basic_string_view::to_string Date: Mon, 29 Jun 2020 13:08:10 -0600 Message-Id: <20200629190810.4758-1-tromey@adacore.com> X-Mailer: git-send-email 2.21.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_BARRACUDACENTRAL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 29 Jun 2020 19:08:14 -0000 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-29 Tom Tromey PR build/26183: * ada-lang.c (ada_lookup_name_info::ada_lookup_name_info): Use gdb::to_string. gdbsupport/ChangeLog 2020-06-29 Tom Tromey PR build/26183: * gdb_string_view.h (basic_string_view::to_string): Remove. (gdb::to_string): New function. --- gdb/ChangeLog | 6 ++++++ gdb/ada-lang.c | 8 ++++---- gdbsupport/ChangeLog | 6 ++++++ gdbsupport/gdb_string_view.h | 17 ++++++++++------- 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 9b0c2efbfe2..98508c168bc 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -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. */ diff --git a/gdbsupport/gdb_string_view.h b/gdbsupport/gdb_string_view.h index c0ae7a8a2d9..65124e67e54 100644 --- a/gdbsupport/gdb_string_view.h +++ b/gdbsupport/gdb_string_view.h @@ -245,13 +245,6 @@ namespace gdb { return { this->_M_str, this->_M_len }; } - template> - 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 */ -- 2.21.3