diff --git a/include/wx/defs.h b/include/wx/defs.h index 07533d00f6..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. 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/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/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/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)