[lldb-dev] Unifying ctor+Clear() inits into in-class initializers?
Leonard Mosescu via lldb-dev
lldb-dev at lists.llvm.org
Mon Nov 20 11:57:28 PST 2017
>
> void Clear() {
> this->~ClassName();
> new (this) ClassName();
> }
My 2c: this is clever, but not without downsides:
1. It may do more than intended (it will destroy all members / bases)
2. It forces construction and 'reset' to be exactly the same, which is not
always desirable
3. Most importantly if you really want a freshly initialized object, just
do that (create a new object)
I like in-class initializers, but for clear/reset operations I prefer a
standalone operation. And as Pavel suggested, calling 'clear' from the
constructor is a good way to factor out commonality.
On Sun, Nov 19, 2017 at 6:58 AM, Jan Kratochvil via lldb-dev <
lldb-dev at lists.llvm.org> wrote:
> Hi,
>
> https://reviews.llvm.org/D40212
>
> At least DWARFCompileUnit and I see even for example MachVMRegion duplicate
> intialization of fields in both their constructor and Clear(). Moreover
> the
> initialization is in different place than declaration of the member
> variable.
>
> Is it OK to just use in-class member variable initializers and:
> void Clear() {
> this->~ClassName();
> new (this) ClassName();
> }
> ?
>
> Pavel Labath otherwise suggests to just call Clear() from the constructor.
> Still then I find the code could be more readable with in-class members
> initializers - moreover during further refactorizations+extensions.
>
>
> Thanks,
> Jan Kratochvil
> _______________________________________________
> lldb-dev mailing list
> lldb-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20171120/77364e5f/attachment.html>
More information about the lldb-dev
mailing list