From 5c249cbca98c57a0ad04ebe301a32c95e8556214 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 25 Apr 2024 00:39:34 +0200 Subject: [PATCH] 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. --- docs/changes.txt | 1 + include/wx/brush.h | 1 + include/wx/colour.h | 3 ++- include/wx/defs.h | 14 ++++++++++++++ include/wx/font.h | 3 ++- include/wx/generic/accel.h | 3 +++ include/wx/generic/colour.h | 5 +---- include/wx/generic/paletteg.h | 3 +++ include/wx/graphics.h | 5 +++++ include/wx/gtk/bitmap.h | 3 +++ include/wx/gtk/brush.h | 3 +++ include/wx/gtk/colour.h | 2 ++ include/wx/gtk/cursor.h | 2 ++ include/wx/gtk/font.h | 2 ++ include/wx/gtk/pen.h | 2 ++ include/wx/palette.h | 2 ++ include/wx/pen.h | 1 + 17 files changed, 49 insertions(+), 6 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index f55f5d48fc..678c3f4895 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -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: diff --git a/include/wx/brush.h b/include/wx/brush.h index 1ca1f1ff09..98c204cc8f 100644 --- a/include/wx/brush.h +++ b/include/wx/brush.h @@ -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; diff --git a/include/wx/colour.h b/include/wx/colour.h index 22a145ab22..7413b28000 100644 --- a/include/wx/colour.h +++ b/include/wx/colour.h @@ -88,7 +88,8 @@ public: // type of a single colour component typedef unsigned char ChannelType; - wxColourBase() {} + wxDECLARE_DEFAULT_COPY_AND_DEF(wxColourBase) + virtual ~wxColourBase() {} diff --git a/include/wx/defs.h b/include/wx/defs.h index c6cfac6dbb..39ce129477 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -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) \ diff --git a/include/wx/font.h b/include/wx/font.h index 428840d3b3..23f2cdb2d7 100644 --- a/include/wx/font.h +++ b/include/wx/font.h @@ -341,7 +341,8 @@ public: wxFontEncoding encoding = wxFONTENCODING_DEFAULT); */ - // creator function + wxDECLARE_DEFAULT_COPY_AND_DEF(wxFontBase) + virtual ~wxFontBase(); diff --git a/include/wx/generic/accel.h b/include/wx/generic/accel.h index 0195f4642b..95074b971d 100644 --- a/include/wx/generic/accel.h +++ b/include/wx/generic/accel.h @@ -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(); } diff --git a/include/wx/generic/colour.h b/include/wx/generic/colour.h index 8ef0ccb7c6..af9c654944 100644 --- a/include/wx/generic/colour.h +++ b/include/wx/generic/colour.h @@ -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); diff --git a/include/wx/generic/paletteg.h b/include/wx/generic/paletteg.h index a475c7d18f..603540224d 100644 --- a/include/wx/generic/paletteg.h +++ b/include/wx/generic/paletteg.h @@ -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); diff --git a/include/wx/graphics.h b/include/wx/graphics.h index 0986a2cf3f..e12e074668 100644 --- a/include/wx/graphics.h +++ b/include/wx/graphics.h @@ -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 diff --git a/include/wx/gtk/bitmap.h b/include/wx/gtk/bitmap.h index ba6902db6d..fa6c55f61e 100644 --- a/include/wx/gtk/bitmap.h +++ b/include/wx/gtk/bitmap.h @@ -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; diff --git a/include/wx/gtk/brush.h b/include/wx/gtk/brush.h index 7f88eb1aef..2eadf1e94c 100644 --- a/include/wx/gtk/brush.h +++ b/include/wx/gtk/brush.h @@ -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; diff --git a/include/wx/gtk/colour.h b/include/wx/gtk/colour.h index 86e74e5720..91b40a02e4 100644 --- a/include/wx/gtk/colour.h +++ b/include/wx/gtk/colour.h @@ -28,6 +28,8 @@ public: wxColour(const GdkRGBA& gdkRGBA); #endif + wxDECLARE_DEFAULT_COPY(wxColour) + virtual ~wxColour(); bool operator==(const wxColour& col) const; diff --git a/include/wx/gtk/cursor.h b/include/wx/gtk/cursor.h index 439cbf91d4..9ff7666421 100644 --- a/include/wx/gtk/cursor.h +++ b/include/wx/gtk/cursor.h @@ -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(); diff --git a/include/wx/gtk/font.h b/include/wx/gtk/font.h index e2e57b146d..797f9011e9 100644 --- a/include/wx/gtk/font.h +++ b/include/wx/gtk/font.h @@ -50,6 +50,8 @@ public: SetPixelSize(pixelSize); } + wxDECLARE_DEFAULT_COPY(wxFont) + bool Create(int size, wxFontFamily family, wxFontStyle style, diff --git a/include/wx/gtk/pen.h b/include/wx/gtk/pen.h index 6e95eb9c40..579f2fc9dc 100644 --- a/include/wx/gtk/pen.h +++ b/include/wx/gtk/pen.h @@ -22,6 +22,8 @@ public: wxPen( const wxPenInfo& info ); + wxDECLARE_DEFAULT_COPY(wxPen) + virtual ~wxPen(); bool operator==(const wxPen& pen) const; diff --git a/include/wx/palette.h b/include/wx/palette.h index 00aa960159..dd5d4ce18d 100644 --- a/include/wx/palette.h +++ b/include/wx/palette.h @@ -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; } diff --git a/include/wx/pen.h b/include/wx/pen.h index 8fbdeabad9..c5c751d4db 100644 --- a/include/wx/pen.h +++ b/include/wx/pen.h @@ -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;