MSVC 2015 & error C2280 & deleted function

Post here wxCrafter related issues / features / bugs
coder99
CodeLite Expert
Posts: 167
Joined: Wed Oct 22, 2008 6:50 am
Contact:

MSVC 2015 & error C2280 & deleted function

Post by coder99 »

Over the past few days, I have been reworking an older project, moving from wxFormBuilder & MSVC 2015 to wxCrafter & MSVC 2015 & wxWidgets 3.1

After converting three wxFB projects to wxCrafter and compiling under MSVC 2015 I get a number of curious error messages, such as
"error C2280: 'MyDosExeDbCtlDialog::MyDosExeDbCtlDialog(const MyDosExeDbCtlDialog &)': attempting to reference a deleted function"
where MyDosExeDbCtlDialog is derived from class LdrPluginDbCtlBaseDialog : public wxDialog which in turn is created by the newly imported class from the wxFB project.

Googling the error message convinced me that this is due to more stringent parsing by the MSVC 2015 C++ compiler and one of the comments quotes:
If the class definition does not explicitly declare a copy constructor, a non-explicit one is declared implicitly. If the class definition declares a move constructor or move assignment operator, the implicitly declared copy constructor is defined as deleted; otherwise, it is defined as defaulted (8.4). The latter case is deprecated if the class has a user-declared copy assignment operator or a user-declared destructor.
As it is, I haven't quite wrapped my mind around all of this and I am not really trying to blame wxCrafter for this error message, but I am very curious to not only find a solution, but also to figure out why not every dialog created in wxFB/wxCrafter gives me the same error message.
Unfortunately, this is part of a rather large project with a couple of dozen or so sub-projects, including a wxWidgets main project, using wxWidgets DLLs with DLL plugins,so it would be a major job to try and whittle this down to a relatively small project which still show the problem.
The main project includes 9 different dialogs all handled by wxCrafter, but only 3 raise this error when their derived dialogs are instantiated.

Any thought or comment will be greatly appreciated
TIA

Win 10/11 64-bit, MSVC 2019/2022, wxWidgets 3.2.1, CodeLite 17.0 Mint 21.2

User avatar
eranif
CodeLite Plugin
Posts: 6375
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: MSVC 2015 & error C2280 & deleted function

Post by eranif »

Note that wxCrafter does not create copy ctor for you. Maybe wxFB declares one and this got lost in the transfer?
Make sure you have read the HOW TO POST thread
coder99
CodeLite Expert
Posts: 167
Joined: Wed Oct 22, 2008 6:50 am
Contact:

Re: MSVC 2015 & error C2280 & deleted function

Post by coder99 »

Thank you, Eran. I had thought something along those lines, but had not been able to find _any_ copy ctors anywhere in the old code.
Today I took some time to look into this issue a bit more.
As you said, wxCrafter does not create a copy ctor and as far as I can see neither does/did wxFB, so nothing was lost in the conversion.
Again, as far I as remember, I never have (or had found the need to) added such a copy ctor to any of my other projects before or after moving them to either wxCrafter and/or MSVC2015, and I have a good number of these.
The curious thing was and still is why only some dialogs produced the problem and I still cannot figure that one out either, but ...
adding some sort of 'dummy' copy ctor to the base code created by wxCrafter allowed the compile to complete without the error.
Adding such a ctor to the derived classes did not seem to work for me.
In the base header, for the one class which caused the error, I have added:

Code: Select all

class MyBaseNewAddressDialog : public wxDialog
{
protected:
    wxTextCtrl* m_textCtrlNewAddr;  ....
protected:
public:
    wxTextCtrl* GetTextCtrlNewAddr() { return m_textCtrlNewAddr; }
    ....
    MyBaseNewAddressDialog(wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT(""), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize(-1,-1), long style = wxDEFAULT_DIALOG_STYLE);
    virtual ~MyBaseNewAddressDialog();
   MyBaseNewAddressDialog( const MyBaseNewAddressDialog& base );  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
};
and in the class code file:

Code: Select all

MyBaseNewAddressDialog::MyBaseNewAddressDialog( const MyBaseNewAddressDialog& base ){}  <<<<<<<<<<<<<<<<<<<<<<<<<<

MyBaseNewAddressDialog::MyBaseNewAddressDialog(wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style)
    : wxDialog(parent, id, title, pos, size, style)
{
}
Beyond a clean compile, I have not tried run the code because I have other issues, most likely introduced by my move to wxWidgets 3.1, but now that I get at least a clean compile, I can investigate these other issues.
The only problem now, of course, is that I have to fiddle the wxCrafter code each time I make any changes to the GUI :-(

Win 10/11 64-bit, MSVC 2019/2022, wxWidgets 3.2.1, CodeLite 17.0 Mint 21.2

User avatar
Jarod42
CodeLite Expert
Posts: 240
Joined: Wed Sep 30, 2009 5:54 pm
Genuine User: Yes
IDE Question: C++
Location: France
Contact:

Re: MSVC 2015 & error C2280 & deleted function

Post by Jarod42 »

Deleting explicitly the copy constructor may produce better error message or spot where the constructor is used.
coder99
CodeLite Expert
Posts: 167
Joined: Wed Oct 22, 2008 6:50 am
Contact:

Re: MSVC 2015 & error C2280 & deleted function

Post by coder99 »

Thank you for the suggestion.
In the meantime, I had to suspend work on these 'old' projects to get on with some other work, but when I get back to them, I'll certainly follow up on this trail.

Win 10/11 64-bit, MSVC 2019/2022, wxWidgets 3.2.1, CodeLite 17.0 Mint 21.2

Post Reply