[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lmi] [lmi-commits] master a67848a 1/3: Use 'new(wx)' to allocate me
From: |
Greg Chicares |
Subject: |
Re: [lmi] [lmi-commits] master a67848a 1/3: Use 'new(wx)' to allocate memory that will be freed by wx |
Date: |
Mon, 8 Feb 2021 22:11:00 +0000 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0 |
On 2/8/21 11:30 AM, Vadim Zeitlin wrote:
> On Sun, 7 Feb 2021 23:17:08 +0000 Greg Chicares <gchicares@sbcglobal.net>
> wrote:
[...]
> GC> Would we write
> GC> std::unique_ptr<InputSequenceEntry> z = new(wx) InputSequenceEntry(...);
> GC> because there's no make_unique(wx) that would delegate to new(wx)?
>
> I could be wrong, but I thought we only need to use new(wx) for the
> pointers deleted by wxWidgets. And normally this is the case for all window
> pointers that we create in lmi code, which is why we use new(wx) for all of
> them. However in this particular case we want to delete the window
> ourselves, so it won't be deleted by wxWidgets and hence there is no need
> for new(wx) and we can just write
>
> auto const z = std::make_unique<InputSequenceEntry>(...);
Should it be easy to write that in a way that compiles? I tried:
diff --git a/skeleton.cpp b/skeleton.cpp
index 267582eba..b37aa3fbf 100644
--- a/skeleton.cpp
+++ b/skeleton.cpp
@@ -1081,7 +1081,8 @@ void
Skeleton::UponTestFloatingPointEnvironment(wxCommandEvent&)
void Skeleton::UponTestPasting(wxCommandEvent&)
{
- InputSequenceEntry* z = new(wx) InputSequenceEntry(frame_, wxID_ANY,
"Testing...");
+ auto const z = std::make_unique<InputSequenceEntry>
+ (InputSequenceEntry(frame_, wxID_ANY, "Testing..."));
wxTextCtrl& t = z->text_ctrl();
ClipboardEx::SetText("1\r\n2\r\n3\r\n");
@@ -1100,7 +1101,6 @@ void Skeleton::UponTestPasting(wxCommandEvent&)
warning() << "'X;Y;Z;' != '" << t.GetValue() << "'" << LMI_FLUSH;
}
- z->Destroy();
status() << "Pasting test finished." << std::flush;
}
but gcc complains:
/usr/lib/gcc/i686-w64-mingw32/8.3-win32/include/c++/bits/unique_ptr.h: In
instantiation of ‘typename std::_MakeUniq<_Tp>::__single_object
std::make_unique(_Args&& ...) [with _Tp = InputSequenceEntry; _Args =
{InputSequenceEntry}; typename std::_MakeUniq<_Tp>::__single_object =
std::unique_ptr<InputSequenceEntry, std::default_delete<InputSequenceEntry> >]’:
/opt/lmi/src/lmi/skeleton.cpp:1085:60: required from here
/usr/lib/gcc/i686-w64-mingw32/8.3-win32/include/c++/bits/unique_ptr.h:827:30:
error: use of deleted function ‘InputSequenceEntry::InputSequenceEntry(const
InputSequenceEntry&)’
{ return unique_ptr<_Tp>(new _Tp(std::forward<_Args>(__args)...)); }
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /opt/lmi/src/lmi/skeleton.cpp:61:
/opt/lmi/src/lmi/input_sequence_entry.hpp:44:5: note: declared here
InputSequenceEntry(InputSequenceEntry const&) = delete;
^~~~~~~~~~~~~~~~~~
I even tried making it a shared_ptr, in the hope that that would
be less fussy, but got similar diagnostics.
Is there something unholy about class InputSequenceEntry that makes
this fail? I thought that shared_ptr<T> in particular placed no
requirements on type T other than that T::~T() mustn't throw.