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..07533d00f6 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -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(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 +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 */ /* ---------------------------------------------------------------------------- */ 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/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/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 {