Avoid warnings about operations on different enums in C++20 mode
Arithmetic operations on the elements of different enums are deprecated in C++20 and the latest compiler versions warn about them. While individual warnings could be fixed in wxWidgets itself (although it would be quite an effort to do it for all ~500 of them), it wouldn't help with the same warnings in the applications using wx, so prefer to do it by explicitly defining the operations on the enums that can be combined with each other by using wxALLOW_COMBINING_ENUMS() macro, except for a single warning in wxTar code where it's easier to just not use an anum at all.
This commit is contained in:
parent
5ab5172930
commit
3d278ee75f
@ -55,6 +55,7 @@ enum wxAuiNotebookOption
|
||||
wxAUI_NB_MIDDLE_CLICK_CLOSE
|
||||
};
|
||||
|
||||
wxALLOW_COMBINING_ENUMS(wxAuiNotebookOption, wxBorder)
|
||||
|
||||
|
||||
|
||||
|
@ -1255,6 +1255,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 +1402,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 */
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
|
@ -345,6 +345,8 @@ enum wxTextBoxAttrPosition
|
||||
wxTEXT_BOX_ATTR_POSITION_MASK = 0x00F0
|
||||
};
|
||||
|
||||
wxALLOW_COMBINING_ENUMS(wxTextAttrUnits, wxTextAttrValueFlags)
|
||||
|
||||
/**
|
||||
@class wxTextAttrDimension
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -58,9 +58,7 @@ enum {
|
||||
TAR_NUMFIELDS
|
||||
};
|
||||
|
||||
enum {
|
||||
TAR_BLOCKSIZE = 512
|
||||
};
|
||||
static const int TAR_BLOCKSIZE = 512;
|
||||
|
||||
// checksum type
|
||||
enum {
|
||||
|
Loading…
Reference in New Issue
Block a user