Merge branch 'cxx20-warning-fixes'

Build fixes for gcc 11 and clang 12, including in C++ 20 mode.

See https://github.com/wxWidgets/wxWidgets/pull/2347
This commit is contained in:
Vadim Zeitlin
2021-04-26 16:10:33 +02:00
14 changed files with 104 additions and 32 deletions

View File

@@ -55,6 +55,7 @@ enum wxAuiNotebookOption
wxAUI_NB_MIDDLE_CLICK_CLOSE
};
wxALLOW_COMBINING_ENUMS(wxAuiNotebookOption, wxBorder)

View File

@@ -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<int>(v1) | static_cast<int>(v2); } \
inline int operator+(en1 v1, en2 v2) \
{ return static_cast<int>(v1) + static_cast<int>(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 */
/* ---------------------------------------------------------------------------- */

View File

@@ -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

View File

@@ -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;

View File

@@ -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

View File

@@ -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)

View File

@@ -345,6 +345,8 @@ enum wxTextBoxAttrPosition
wxTEXT_BOX_ATTR_POSITION_MASK = 0x00F0
};
wxALLOW_COMBINING_ENUMS(wxTextAttrUnits, wxTextAttrValueFlags)
/**
@class wxTextAttrDimension

View File

@@ -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

View File

@@ -295,7 +295,7 @@ struct wxFormatStringArgumentFinder<wxScopedCharBuffer>
: public wxFormatStringArgumentFinder<const wxScopedCharBuffer&> {
#ifdef wxNO_IMPLICIT_WXSTRING_ENCODING
private:
wxFormatStringArgumentFinder<wxScopedCharBuffer>(); // Disabled
wxFormatStringArgumentFinder() wxMEMBER_DELETE;
#endif // wxNO_IMPLICIT_WXSTRING_ENCODING
};
@@ -308,7 +308,7 @@ struct wxFormatStringArgumentFinder<wxCharBuffer>
: public wxFormatStringArgumentFinder<const wxCharBuffer&> {
#ifdef wxNO_IMPLICIT_WXSTRING_ENCODING
private:
wxFormatStringArgumentFinder<wxCharBuffer>(); // Disabled
wxFormatStringArgumentFinder() wxMEMBER_DELETE;
#endif // wxNO_IMPLICIT_WXSTRING_ENCODING
};
@@ -409,7 +409,7 @@ struct wxFormatStringSpecifier<const T*>
template<> struct wxFormatStringSpecifier<T> \
{ \
private: \
wxFormatStringSpecifier<T>(); /* Disabled */ \
wxFormatStringSpecifier() wxMEMBER_DELETE; \
};
wxFORMAT_STRING_SPECIFIER(bool, wxFormatString::Arg_Int)
@@ -689,42 +689,37 @@ struct wxArgNormalizerWchar<const wchar_t*>
template<>
struct wxArgNormalizer<const char*> {
private:
wxArgNormalizer<const char*>(const char*, const wxFormatString *,
unsigned);
wxArgNormalizer(const char*, const wxFormatString *, unsigned);
const char *get() const;
};
template<>
struct wxArgNormalizer<char*> {
private:
wxArgNormalizer<char*>(const char*, const wxFormatString *, unsigned);
wxArgNormalizer(const char*, const wxFormatString *, unsigned);
char *get() const;
};
template<>
struct wxArgNormalizer<const std::string> {
private:
wxArgNormalizer<const std::string>(const std::string&,
const wxFormatString *, unsigned);
wxArgNormalizer(const std::string&, const wxFormatString *, unsigned);
std::string get() const;
};
template<>
struct wxArgNormalizer<std::string> {
private:
wxArgNormalizer<std::string>(std::string&,
const wxFormatString *, unsigned);
wxArgNormalizer(std::string&, const wxFormatString *, unsigned);
std::string get() const;
};
template<>
struct wxArgNormalizer<wxCharBuffer> {
private:
wxArgNormalizer<wxCharBuffer>(wxCharBuffer&,
const wxFormatString *, unsigned);
wxArgNormalizer(wxCharBuffer&, const wxFormatString *, unsigned);
std::string get() const;
};
template<>
struct wxArgNormalizer<wxScopedCharBuffer> {
private:
wxArgNormalizer<wxScopedCharBuffer>(wxScopedCharBuffer&,
const wxFormatString *, unsigned);
wxArgNormalizer(wxScopedCharBuffer&, const wxFormatString *, unsigned);
std::string get() const;
};
#endif // wxNO_IMPLICIT_WXSTRING_ENCODING

View File

@@ -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

View File

@@ -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

View File

@@ -58,9 +58,7 @@ enum {
TAR_NUMFIELDS
};
enum {
TAR_BLOCKSIZE = 512
};
static const int TAR_BLOCKSIZE = 512;
// checksum type
enum {

View File

@@ -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,

View File

@@ -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)