diff --git a/include/wx/aui/auibook.h b/include/wx/aui/auibook.h index dc3f509510..23d66ade71 100644 --- a/include/wx/aui/auibook.h +++ b/include/wx/aui/auibook.h @@ -55,6 +55,7 @@ enum wxAuiNotebookOption wxAUI_NB_MIDDLE_CLICK_CLOSE }; +wxALLOW_COMBINING_ENUMS(wxAuiNotebookOption, wxBorder) diff --git a/include/wx/defs.h b/include/wx/defs.h index d98dac5354..629706b1c8 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -740,6 +740,17 @@ typedef short int WXTYPE; # define wxWARNING_RESTORE_MISSING_OVERRIDE() #endif +/* + Macros above don't work with gcc 11 due to a compiler bug, unless we also + use "override" in the function declaration -- but this breaks other + compilers, so define a specific macro for gcc 11 only. + */ +#if wxCHECK_GCC_VERSION(11, 0) +# define wxDUMMY_OVERRIDE wxOVERRIDE +#else +# define wxDUMMY_OVERRIDE +#endif + /* Combination of the two variants above: should be used for deprecated functions which are defined inline and are used by wxWidgets itself. @@ -1255,6 +1266,28 @@ typedef double wxDouble; /* Geometric flags */ /* ---------------------------------------------------------------------------- */ +/* + In C++20 operations on the elements of different enums are deprecated and + many compilers (clang 10+, gcc 11+, MSVS 2019) warn about combining them, + as a lot of existing code using them does, so we provide explicit operators + for doing this, that do the same thing as would happen without them, but + without the warnings. + */ +#if defined(__cplusplus) && (__cplusplus >= 202002L) + #define wxALLOW_COMBINING_ENUMS_IMPL(en1, en2) \ + inline int operator|(en1 v1, en2 v2) \ + { return static_cast(v1) | static_cast(v2); } \ + inline int operator+(en1 v1, en2 v2) \ + { return static_cast(v1) + static_cast(v2); } + + #define wxALLOW_COMBINING_ENUMS(en1, en2) \ + wxALLOW_COMBINING_ENUMS_IMPL(en1, en2) \ + wxALLOW_COMBINING_ENUMS_IMPL(en2, en1) +#else /* !C++ 20 */ + /* Don't bother doing anything in this case. */ + #define wxALLOW_COMBINING_ENUMS(en1, en2) +#endif /* C++ 20 */ + enum wxGeometryCentre { wxCENTRE = 0x0001, @@ -1380,6 +1413,16 @@ enum wxBorder /* This makes it easier to specify a 'normal' border for a control */ #define wxDEFAULT_CONTROL_BORDER wxBORDER_SUNKEN +/* + Elements of these enums can be combined with each other when using + wxSizer::Add() overload not using wxSizerFlags. + */ +wxALLOW_COMBINING_ENUMS(wxAlignment, wxDirection) +wxALLOW_COMBINING_ENUMS(wxAlignment, wxGeometryCentre) +wxALLOW_COMBINING_ENUMS(wxAlignment, wxStretch) +wxALLOW_COMBINING_ENUMS(wxDirection, wxStretch) +wxALLOW_COMBINING_ENUMS(wxDirection, wxGeometryCentre) + /* ---------------------------------------------------------------------------- */ /* Window style flags */ /* ---------------------------------------------------------------------------- */ diff --git a/include/wx/event.h b/include/wx/event.h index c14b5def97..c649d2fb8f 100644 --- a/include/wx/event.h +++ b/include/wx/event.h @@ -4322,8 +4322,8 @@ typedef void (wxEvtHandler::*wxPressAndTapEventFunction)(wxPressAndTapEvent&); static const wxEventTableEntry sm_eventTableEntries[]; \ protected: \ wxWARNING_SUPPRESS_MISSING_OVERRIDE() \ - const wxEventTable* GetEventTable() const; \ - wxEventHashTable& GetEventHashTable() const; \ + const wxEventTable* GetEventTable() const wxDUMMY_OVERRIDE; \ + wxEventHashTable& GetEventHashTable() const wxDUMMY_OVERRIDE; \ wxWARNING_RESTORE_MISSING_OVERRIDE() \ static const wxEventTable sm_eventTable; \ static wxEventHashTable sm_eventHashTable diff --git a/include/wx/font.h b/include/wx/font.h index 938e6aeaf1..428840d3b3 100644 --- a/include/wx/font.h +++ b/include/wx/font.h @@ -395,8 +395,8 @@ public: #endif // wxUSE_PRIVATE_FONTS // comparison - bool operator==(const wxFont& font) const; - bool operator!=(const wxFont& font) const { return !(*this == font); } + bool operator==(const wxFontBase& font) const; + bool operator!=(const wxFontBase& font) const { return !(*this == font); } // accessors: get the font characteristics virtual int GetPointSize() const; diff --git a/include/wx/gtk/dataform.h b/include/wx/gtk/dataform.h index 9389a99765..ae5a2c232b 100644 --- a/include/wx/gtk/dataform.h +++ b/include/wx/gtk/dataform.h @@ -33,15 +33,18 @@ public: wxDataFormat& operator=(NativeFormat format) { SetId(format); return *this; } - // comparison (must have both versions) + // comparison (note that we rely on implicit conversions for comparison + // with wxDataFormatId, but have to provide them explicitly for comparison + // with NativeFormat to avoid ambiguity between comparing from it to + // wxDataFormat or vice versa) bool operator==(NativeFormat format) const { return m_format == (NativeFormat)format; } bool operator!=(NativeFormat format) const { return m_format != (NativeFormat)format; } - bool operator==(wxDataFormatId format) const - { return m_type == (wxDataFormatId)format; } - bool operator!=(wxDataFormatId format) const - { return m_type != (wxDataFormatId)format; } + bool operator==(const wxDataFormat& other) const + { return m_format == other.m_format; } + bool operator!=(const wxDataFormat& other) const + { return m_format != other.m_format; } // explicit and implicit conversions to NativeFormat which is one of // standard data types (implicit conversion is useful for preserving the diff --git a/include/wx/object.h b/include/wx/object.h index e4baee1396..4ec2bc457f 100644 --- a/include/wx/object.h +++ b/include/wx/object.h @@ -368,8 +368,6 @@ private: class WXDLLIMPEXP_BASE wxObject { - wxDECLARE_ABSTRACT_CLASS(wxObject); - public: wxObject() { m_refData = NULL; } virtual ~wxObject() { UnRef(); } @@ -392,6 +390,7 @@ public: bool IsKindOf(const wxClassInfo *info) const; + virtual wxClassInfo *GetClassInfo() const; // Turn on the correct set of new and delete operators @@ -453,6 +452,8 @@ protected: virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; wxObjectRefData *m_refData; + + static wxClassInfo ms_classInfo; }; inline wxObject *wxCheckDynamicCast(wxObject *obj, wxClassInfo *classInfo) diff --git a/include/wx/richtext/richtextbuffer.h b/include/wx/richtext/richtextbuffer.h index 13e1dfb867..132667c50c 100644 --- a/include/wx/richtext/richtextbuffer.h +++ b/include/wx/richtext/richtextbuffer.h @@ -345,6 +345,8 @@ enum wxTextBoxAttrPosition wxTEXT_BOX_ATTR_POSITION_MASK = 0x00F0 }; +wxALLOW_COMBINING_ENUMS(wxTextAttrUnits, wxTextAttrValueFlags) + /** @class wxTextAttrDimension diff --git a/include/wx/rtti.h b/include/wx/rtti.h index 09faa06d51..0f54a0b914 100644 --- a/include/wx/rtti.h +++ b/include/wx/rtti.h @@ -140,7 +140,7 @@ WXDLLIMPEXP_BASE wxObject *wxCreateDynamicObject(const wxString& name); #define wxDECLARE_ABSTRACT_CLASS(name) \ public: \ wxWARNING_SUPPRESS_MISSING_OVERRIDE() \ - virtual wxClassInfo *GetClassInfo() const; \ + virtual wxClassInfo *GetClassInfo() const wxDUMMY_OVERRIDE; \ wxWARNING_RESTORE_MISSING_OVERRIDE() \ static wxClassInfo ms_classInfo diff --git a/include/wx/strvararg.h b/include/wx/strvararg.h index 0abf59b1b3..95f2369263 100644 --- a/include/wx/strvararg.h +++ b/include/wx/strvararg.h @@ -295,7 +295,7 @@ struct wxFormatStringArgumentFinder : public wxFormatStringArgumentFinder { #ifdef wxNO_IMPLICIT_WXSTRING_ENCODING private: - wxFormatStringArgumentFinder(); // Disabled + wxFormatStringArgumentFinder() wxMEMBER_DELETE; #endif // wxNO_IMPLICIT_WXSTRING_ENCODING }; @@ -308,7 +308,7 @@ struct wxFormatStringArgumentFinder : public wxFormatStringArgumentFinder { #ifdef wxNO_IMPLICIT_WXSTRING_ENCODING private: - wxFormatStringArgumentFinder(); // Disabled + wxFormatStringArgumentFinder() wxMEMBER_DELETE; #endif // wxNO_IMPLICIT_WXSTRING_ENCODING }; @@ -409,7 +409,7 @@ struct wxFormatStringSpecifier template<> struct wxFormatStringSpecifier \ { \ private: \ - wxFormatStringSpecifier(); /* Disabled */ \ + wxFormatStringSpecifier() wxMEMBER_DELETE; \ }; wxFORMAT_STRING_SPECIFIER(bool, wxFormatString::Arg_Int) @@ -689,42 +689,37 @@ struct wxArgNormalizerWchar template<> struct wxArgNormalizer { private: - wxArgNormalizer(const char*, const wxFormatString *, - unsigned); + wxArgNormalizer(const char*, const wxFormatString *, unsigned); const char *get() const; }; template<> struct wxArgNormalizer { private: - wxArgNormalizer(const char*, const wxFormatString *, unsigned); + wxArgNormalizer(const char*, const wxFormatString *, unsigned); char *get() const; }; template<> struct wxArgNormalizer { private: - wxArgNormalizer(const std::string&, - const wxFormatString *, unsigned); + wxArgNormalizer(const std::string&, const wxFormatString *, unsigned); std::string get() const; }; template<> struct wxArgNormalizer { private: - wxArgNormalizer(std::string&, - const wxFormatString *, unsigned); + wxArgNormalizer(std::string&, const wxFormatString *, unsigned); std::string get() const; }; template<> struct wxArgNormalizer { private: - wxArgNormalizer(wxCharBuffer&, - const wxFormatString *, unsigned); + wxArgNormalizer(wxCharBuffer&, const wxFormatString *, unsigned); std::string get() const; }; template<> struct wxArgNormalizer { private: - wxArgNormalizer(wxScopedCharBuffer&, - const wxFormatString *, unsigned); + wxArgNormalizer(wxScopedCharBuffer&, const wxFormatString *, unsigned); std::string get() const; }; #endif // wxNO_IMPLICIT_WXSTRING_ENCODING diff --git a/include/wx/toolbar.h b/include/wx/toolbar.h index 3aacb1f27d..f6a3a766f0 100644 --- a/include/wx/toolbar.h +++ b/include/wx/toolbar.h @@ -17,7 +17,7 @@ // wxToolBar style flags // ---------------------------------------------------------------------------- -enum +enum wxToolBarStyleFlags { // lay out the toolbar horizontally wxTB_HORIZONTAL = wxHORIZONTAL, // == 0x0004 @@ -61,6 +61,8 @@ enum wxTB_DEFAULT_STYLE = wxTB_HORIZONTAL }; +wxALLOW_COMBINING_ENUMS(wxToolBarStyleFlags, wxBorder) + #if wxUSE_TOOLBAR #include "wx/tbarbase.h" // the base class for all toolbars diff --git a/src/common/fontcmn.cpp b/src/common/fontcmn.cpp index 3ae09d0f49..96082ed375 100644 --- a/src/common/fontcmn.cpp +++ b/src/common/fontcmn.cpp @@ -425,7 +425,7 @@ bool wxFontBase::SetNativeFontInfoUserDesc(const wxString& info) return false; } -bool wxFontBase::operator==(const wxFont& font) const +bool wxFontBase::operator==(const wxFontBase& font) const { // either it is the same font, i.e. they share the same common data or they // have different ref datas but still describe the same font diff --git a/src/common/tarstrm.cpp b/src/common/tarstrm.cpp index 30b584e41d..7324b3ac3c 100644 --- a/src/common/tarstrm.cpp +++ b/src/common/tarstrm.cpp @@ -58,9 +58,7 @@ enum { TAR_NUMFIELDS }; -enum { - TAR_BLOCKSIZE = 512 -}; +static const int TAR_BLOCKSIZE = 512; // checksum type enum { diff --git a/src/gtk/clipbrd.cpp b/src/gtk/clipbrd.cpp index 8cd7b1644d..07fcf02ce3 100644 --- a/src/gtk/clipbrd.cpp +++ b/src/gtk/clipbrd.cpp @@ -317,7 +317,7 @@ selection_handler( GtkWidget *WXUNUSED(widget), // use UTF8_STRING format if requested in Unicode build but just plain // STRING one in ANSI or if explicitly asked in Unicode #if wxUSE_UNICODE - if (format == wxDataFormat(wxDF_UNICODETEXT)) + if (format == wxDF_UNICODETEXT) { gtk_selection_data_set_text( selection_data, diff --git a/tests/allheaders.cpp b/tests/allheaders.cpp index 522885b636..2663573da1 100644 --- a/tests/allheaders.cpp +++ b/tests/allheaders.cpp @@ -387,6 +387,33 @@ #include "allheaders.h" +// Check that using wx macros doesn't result in -Wsuggest-override or +// equivalent warnings in classes using and not using "override". +struct Base : wxEvtHandler +{ + virtual ~Base() { } + + virtual void Foo() { } +}; + +struct DerivedWithoutOverride : Base +{ + void OnIdle(wxIdleEvent&) { } + + wxDECLARE_DYNAMIC_CLASS_NO_COPY(DerivedWithoutOverride); + wxDECLARE_EVENT_TABLE(); +}; + +struct DerivedWithOverride : Base +{ + virtual void Foo() wxOVERRIDE { } + + void OnIdle(wxIdleEvent&) { } + + wxDECLARE_DYNAMIC_CLASS_NO_COPY(DerivedWithOverride); + wxDECLARE_EVENT_TABLE(); +}; + #ifdef GCC_TURN_OFF // Just using REQUIRE() below triggers -Wparentheses, so avoid it. GCC_TURN_OFF(parentheses)