From: Simon Marchi <simon.marchi@polymtl.ca>
To: Andrew Burgess <aburgess@redhat.com>,
"Metzger, Markus T" <markus.t.metzger@intel.com>
Cc: "vries@gcc.gnu.org" <vries@gcc.gnu.org>,
"gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: Re: [PATCH v3] gdb: c++ify btrace_target_info
Date: Mon, 11 Sep 2023 11:27:00 -0400 [thread overview]
Message-ID: <5b40b596-a3f0-42df-9dd9-20af5d0f831b@polymtl.ca> (raw)
In-Reply-To: <87tts0kcs8.fsf@redhat.com>
On 9/11/23 10:25, Andrew Burgess wrote:
> "Metzger, Markus T" <markus.t.metzger@intel.com> writes:
>
>> Hello Andrew,
>>
>>>>>> - gdb::unique_xmalloc_ptr<btrace_target_info> tinfo
>>>>>> - (XCNEW (btrace_target_info));
>>>>>> - tinfo->ptid = ptid;
>>>>>> + std::unique_ptr<linux_btrace_target_info> 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<linux_btrace_target_info> (ptid);
>>>>
>>>> I'm not a fan of 'auto'. So this becomes
>>>>
>>>> std::unique_ptr<linux_btrace_target_info> tinfo
>>>> { gdb::make_unique<linux_btrace_target_info> (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<type> (...);
>>>
>>> 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<type> (...) }
>>
>> is really any better than
>>
>> std::unique_ptr<type> 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
prev parent reply other threads:[~2023-09-11 15:27 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-08 10:53 Markus Metzger
2023-09-08 14:31 ` Simon Marchi
2023-09-11 6:18 ` Metzger, Markus T
2023-09-11 9:17 ` Andrew Burgess
2023-09-11 9:53 ` Metzger, Markus T
2023-09-11 14:25 ` Andrew Burgess
2023-09-11 15:27 ` Simon Marchi [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5b40b596-a3f0-42df-9dd9-20af5d0f831b@polymtl.ca \
--to=simon.marchi@polymtl.ca \
--cc=aburgess@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=markus.t.metzger@intel.com \
--cc=vries@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).