From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id YiBPEr1VEWU3lRwAWB0awg (envelope-from ) for ; Mon, 25 Sep 2023 05:41:17 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=cpbQI/+t; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 3F64E1E0C3; Mon, 25 Sep 2023 05:41:17 -0400 (EDT) Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 2B8821E092 for ; Mon, 25 Sep 2023 05:41:15 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E41CC3858028 for ; Mon, 25 Sep 2023 09:41:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E41CC3858028 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1695634873; bh=rDuUMi+Gas6rqKQT53W2jrEC7zKwLR9wxmQ49JSUi4k=; h=Date:To:Cc:Subject:References:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=cpbQI/+t4tIr3qBoc0HeocyX75/PC9RgNy6Yz4RLMmZn0xHXLyoCjfd/RG2S0tjPV 006FixS9UBzciKk9krf9NaQ4vTOFXv5xqluGdcR6amE9ZTKBXJCHN1VvG8IfAq+4lv bbT3sORXLeNMff3JLyyG+YsethAm2akFj8/okVaw= Received: from lndn.lancelotsix.com (lndn.lancelotsix.com [51.195.220.111]) by sourceware.org (Postfix) with ESMTPS id 61A1C3858CDA for ; Mon, 25 Sep 2023 09:40:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 61A1C3858CDA Received: from octopus (cust120-dsl54.idnet.net [212.69.54.120]) by lndn.lancelotsix.com (Postfix) with ESMTPSA id BAE208177F; Mon, 25 Sep 2023 09:40:50 +0000 (UTC) Date: Mon, 25 Sep 2023 10:40:42 +0100 To: Keith Seitz Cc: Tom Tromey , gdb-patches@sourceware.org Subject: Re: [PATCH] Use string_file::release in some places Message-ID: <20230925094032.jv7wrsfhryklrm7q@octopus> References: <20230921194207.2401885-1-tromey@adacore.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.6.2 (lndn.lancelotsix.com [0.0.0.0]); Mon, 25 Sep 2023 09:40:50 +0000 (UTC) X-Spam-Status: No, score=-5.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Lancelot SIX via Gdb-patches Reply-To: Lancelot SIX Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" On Fri, Sep 22, 2023 at 01:42:22PM -0700, Keith Seitz via Gdb-patches wrote: > On Thu, Sep 21, 2023 at 12:42 PM Tom Tromey via Gdb-patches > wrote: > > > > I found a few spots like: > > > > string_file f; > > std::string x = f.string (); > > > > However, string_file::string returns a 'const std::string &'... so it > > seems to me that this must be copying the string (? I find it hard to > > reason about this in C++). Hi Tom and Keith, I think your assessment is correct. Such case calls the string copy operator[1] (i.e. `std::string::string (const std::string &)` - plus the template expansion). Same goes for the "return f.string ();" cases from a function returning a std::string. FWIW, the changes you made seems good to me. Reviewed-by: Lancelot Six > > I admit, you now have me doubting everything I thought I remembered > on this subject! [TODO: reread the standard literature] > > As far as I can tell, your assessment is at least consistent with what is > done elsewhere, e.g., location.c, ada-lang,c, and just about everywhere > else except the two locations you've identified in this patch. > > Would symtab.c's symbol_to_info_string and valops.c:incomplete_type_hint > also qualify for similar treatment? They use addition assignment, so maybe > that alters the analogy? In those cases, because the += operator is used, there is no move semantics which can be leveraged[2]. This operator can only be used with: - const std::string & (what is currently used) - char - const char * - std::initializer_list C++17 also adds string_view based option, but in all the cases we copy the data from the argument. Best, Lancelot. > > In any case: > Reviewed-by: Keith Seitz > > Keith > [1] https://en.cppreference.com/w/cpp/language/copy_initialization [2] https://en.cppreference.com/w/cpp/string/basic_string/operator%2B%3D