Explicitly define copy ctors etc in classes with virtual dtors

This avoids gcc 14 giving -Wdeprecated-copy-dtor for these classes.

This warning was fixed by fc35ad92bb (Remove unnecessary empty
destructors, 2024-01-26) in master, but we can't remove the dtors in
this branch, so add copy ctors and assignment operators here using new
wxDECLARE_DEFAULT_COPY() and wxDECLARE_DEFAULT_COPY_AND_DEF() macros,
which can be fine-tuned later (e.g. to do it only for gcc 14, if it has
any adverse effects on some other compiler) if necessary.

Note that this also required adding some default ctors, as adding the
copy ctor suppressed the generation of the default compiler-generated
default ctor.

Closes #24502.
This commit is contained in:
Vadim Zeitlin
2024-04-25 21:31:36 +02:00
parent 565a5aab14
commit 5c249cbca9
17 changed files with 49 additions and 6 deletions
+1
View File
@@ -298,6 +298,7 @@ wxGTK:
- Fix handling binary data in wxSecretStore (Martin Corino, #24351).
- Make GTKSuppressDiagnostics(), broken since 3.2.1, work again (#24432).
- Fix wxTE_PROCESS_ENTER in wxGTK comboboxes with autocomplete (#24394).
- Fix -Wdeprecated-copy-dtor warnings in the headers with gcc 14 (#24502).
wxMSW:
+1
View File
@@ -41,6 +41,7 @@ enum wxBrushStyle
class WXDLLIMPEXP_CORE wxBrushBase: public wxGDIObject
{
public:
wxDECLARE_DEFAULT_COPY_AND_DEF(wxBrushBase)
virtual ~wxBrushBase() { }
virtual void SetColour(const wxColour& col) = 0;
+2 -1
View File
@@ -88,7 +88,8 @@ public:
// type of a single colour component
typedef unsigned char ChannelType;
wxColourBase() {}
wxDECLARE_DEFAULT_COPY_AND_DEF(wxColourBase)
virtual ~wxColourBase() {}
+14
View File
@@ -3232,14 +3232,28 @@ typedef const void* WXWidget;
#if defined(__cplusplus) && (__cplusplus >= 201103L || wxCHECK_VISUALC_VERSION(14))
#define wxMEMBER_DELETE = delete
// Note that all these macros don't require a semicolon after them because
// they are empty in the "#else" branch and can't be followed by a
// semicolon in that case.
#define wxDECLARE_DEFAULT_COPY_CTOR(classname) \
public: \
classname(const classname&) = default;
#define wxDECLARE_DEFAULT_COPY(classname) \
wxDECLARE_DEFAULT_COPY_CTOR(classname) \
classname& operator=(const classname&) = default;
#define wxDECLARE_DEFAULT_COPY_AND_DEF(classname) \
classname() = default; \
wxDECLARE_DEFAULT_COPY(classname)
#else
#define wxMEMBER_DELETE
// We can't do this without C++11 "= default".
#define wxDECLARE_DEFAULT_COPY_CTOR(classname)
#define wxDECLARE_DEFAULT_COPY(classname)
#define wxDECLARE_DEFAULT_COPY_AND_DEF(classname)
#endif
#define wxDECLARE_NO_COPY_CLASS(classname) \
+2 -1
View File
@@ -341,7 +341,8 @@ public:
wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
*/
// creator function
wxDECLARE_DEFAULT_COPY_AND_DEF(wxFontBase)
virtual ~wxFontBase();
+3
View File
@@ -20,6 +20,9 @@ class WXDLLIMPEXP_CORE wxAcceleratorTable : public wxObject
public:
wxAcceleratorTable();
wxAcceleratorTable(int n, const wxAcceleratorEntry entries[]);
wxDECLARE_DEFAULT_COPY(wxAcceleratorTable)
virtual ~wxAcceleratorTable();
bool Ok() const { return IsOk(); }
+1 -4
View File
@@ -22,10 +22,7 @@ public:
DEFINE_STD_WXCOLOUR_CONSTRUCTORS
// copy ctors and assignment operators
wxColour(const wxColour& col)
{
*this = col;
}
wxDECLARE_DEFAULT_COPY_CTOR(wxColour)
wxColour& operator=(const wxColour& col);
+3
View File
@@ -31,6 +31,9 @@ class WXDLLIMPEXP_CORE wxPalette: public wxPaletteBase
public:
wxPalette();
wxPalette( int n, const unsigned char *red, const unsigned char *green, const unsigned char *blue );
wxDECLARE_DEFAULT_COPY(wxPalette)
virtual ~wxPalette();
bool Create( int n, const unsigned char *red, const unsigned char *green, const unsigned char *blue);
+5
View File
@@ -129,6 +129,9 @@ class WXDLLIMPEXP_CORE wxGraphicsObject : public wxObject
public:
wxGraphicsObject();
wxGraphicsObject( wxGraphicsRenderer* renderer );
wxDECLARE_DEFAULT_COPY(wxGraphicsObject)
virtual ~wxGraphicsObject();
bool IsNull() const;
@@ -209,6 +212,8 @@ class WXDLLIMPEXP_CORE wxGraphicsMatrix : public wxGraphicsObject
public:
wxGraphicsMatrix() {}
wxDECLARE_DEFAULT_COPY(wxGraphicsMatrix)
virtual ~wxGraphicsMatrix() {}
// concatenates the matrix
+3
View File
@@ -79,6 +79,9 @@ public:
#endif // wxUSE_IMAGE
wxBitmap(GdkPixbuf* pixbuf, int depth = 0);
explicit wxBitmap(const wxCursor& cursor);
wxDECLARE_DEFAULT_COPY(wxBitmap)
virtual ~wxBitmap();
bool Create(int width, int height, int depth = wxBITMAP_SCREEN_DEPTH) wxOVERRIDE;
+3
View File
@@ -23,6 +23,9 @@ public:
wxBrush( const wxColour &colour, wxBrushStyle style = wxBRUSHSTYLE_SOLID );
wxBrush( const wxBitmap &stippleBitmap );
wxDECLARE_DEFAULT_COPY(wxBrush)
virtual ~wxBrush();
bool operator==(const wxBrush& brush) const;
+2
View File
@@ -28,6 +28,8 @@ public:
wxColour(const GdkRGBA& gdkRGBA);
#endif
wxDECLARE_DEFAULT_COPY(wxColour)
virtual ~wxColour();
bool operator==(const wxColour& col) const;
+2
View File
@@ -35,6 +35,8 @@ public:
const char maskBits[] = NULL,
const wxColour* fg = NULL, const wxColour* bg = NULL);
wxDECLARE_DEFAULT_COPY(wxCursor)
virtual wxPoint GetHotSpot() const wxOVERRIDE;
virtual ~wxCursor();
+2
View File
@@ -50,6 +50,8 @@ public:
SetPixelSize(pixelSize);
}
wxDECLARE_DEFAULT_COPY(wxFont)
bool Create(int size,
wxFontFamily family,
wxFontStyle style,
+2
View File
@@ -22,6 +22,8 @@ public:
wxPen( const wxPenInfo& info );
wxDECLARE_DEFAULT_COPY(wxPen)
virtual ~wxPen();
bool operator==(const wxPen& pen) const;
+2
View File
@@ -22,6 +22,8 @@
class WXDLLIMPEXP_CORE wxPaletteBase: public wxGDIObject
{
public:
wxDECLARE_DEFAULT_COPY_AND_DEF(wxPaletteBase)
virtual ~wxPaletteBase() { }
virtual int GetColoursCount() const { wxFAIL_MSG( wxT("not implemented") ); return 0; }
+1
View File
@@ -63,6 +63,7 @@ private:
class WXDLLIMPEXP_CORE wxPenBase : public wxGDIObject
{
public:
wxDECLARE_DEFAULT_COPY_AND_DEF(wxPenBase)
virtual ~wxPenBase() { }
virtual void SetColour(const wxColour& col) = 0;