From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 245FB3858D38 for ; Mon, 11 Sep 2023 15:27:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 245FB3858D38 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=polymtl.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=polymtl.ca Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 38BFR1Vd010108 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 11 Sep 2023 11:27:06 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 38BFR1Vd010108 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polymtl.ca; s=default; t=1694446026; bh=zPWoaUoD/VVRpo3EmuW3aKZtmoAi11OGRAtTcWRzxMU=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=CbHAxkqNJxNMujWQ6FYz5EwCXUQj9C4Ze9Uu3pO69AOCpcBX96aCv8h/jRAj8gxZi MDDyQ9w8nLtfXf5ElftXBjTYFTokTswhS8tKLxn4tMsP9gd/w3ZPJaus7wGN2LZ9Gm 9pJ2KxBnUbmL9juEZl5o3xshmOM2XybmgXJDEgtw= Received: from [172.16.0.192] (192-222-143-198.qc.cable.ebox.net [192.222.143.198]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 513091E092; Mon, 11 Sep 2023 11:27:01 -0400 (EDT) Message-ID: <5b40b596-a3f0-42df-9dd9-20af5d0f831b@polymtl.ca> Date: Mon, 11 Sep 2023 11:27:00 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3] gdb: c++ify btrace_target_info Content-Language: fr To: Andrew Burgess , "Metzger, Markus T" Cc: "vries@gcc.gnu.org" , "gdb-patches@sourceware.org" References: <20230908105319.1963979-1-markus.t.metzger@intel.com> <0d7782da-940c-40da-a511-4f8a36b5455c@polymtl.ca> <87r0n5kr1g.fsf@redhat.com> <87tts0kcs8.fsf@redhat.com> From: Simon Marchi In-Reply-To: <87tts0kcs8.fsf@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Mon, 11 Sep 2023 15:27:01 +0000 X-Spam-Status: No, score=-3031.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 9/11/23 10:25, Andrew Burgess wrote: > "Metzger, Markus T" writes: > >> Hello Andrew, >> >>>>>> - gdb::unique_xmalloc_ptr tinfo >>>>>> - (XCNEW (btrace_target_info)); >>>>>> - tinfo->ptid = ptid; >>>>>> + std::unique_ptr tinfo >>>>>> + { new linux_btrace_target_info { ptid } }; >>>>> >>>>> We recently added a gdb::make_unique function, it would make sense to >>>>> you use it here (it will eventually become std::make_unique once we >>>>> migrate to C++ 14). >>>>> >>>>> So this could be written as: >>>>> >>>>> auto tinfo = gdb::make_unique (ptid); >>>> >>>> I'm not a fan of 'auto'. So this becomes >>>> >>>> std::unique_ptr tinfo >>>> { gdb::make_unique (ptid) }; >>> >>> This really doesn't feel like an improvement. >>> >>> I also try to avoid excessive use of auto, so I dislike things like: >>> >>> auto var = some_function (....); >>> >>> because there's no hint what the type of var actually is (without >>> looking at `some_function`). But in the case of: >>> >>> auto var = gdb::make_unique (...); >>> >>> The type of var is right there on the line, so duplicating the type >>> information is just noise. For me this is a perfect use of auto. >> >> A related question is whether >> >> auto ptr { gdb::make_unique (...) } >> >> is really any better than >> >> std::unique_ptr ptr { new type (...) } > > Well std::make_unique<> exists, so I think like it or not, that's the > preferred C++ approach. > > I thought (though I don't claim to be an expert) that, in general, > direct calls to 'new' were to be avoided in C++ code. > > Thanks, > Andrew I agree with Andrew for his comments on both topics (the non-excessive use of auto and make_unique). Simon