From 8a5d9295b74660b228a510f11854005d4ea1fe42 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 31 Jul 2022 20:00:18 +0200 Subject: [PATCH 1/3] Fix even more warnings about combining different enums in C++20 This completes the changes of 5477d4faa8 (Avoid warnings when combining wxStaticText styles with C++20, 2022-07-20) which, in turn, was based on 3d278ee75f (Avoid warnings about operations on different enums in C++20 mode, 2021-04-25). Also add a test checking that no warnings are given for all possible enum values combinations (but this test is only useful when using C++20). See #22681. --- include/wx/defs.h | 13 +++++++++++-- tests/sizers/boxsizer.cpp | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/include/wx/defs.h b/include/wx/defs.h index cc4bcf07be..400404dd7a 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -1465,12 +1465,21 @@ enum wxBorder Elements of these enums can be combined with each other when using wxSizer::Add() overload not using wxSizerFlags. */ +wxALLOW_COMBINING_ENUMS(wxAlignment, wxBorder) wxALLOW_COMBINING_ENUMS(wxAlignment, wxDirection) wxALLOW_COMBINING_ENUMS(wxAlignment, wxGeometryCentre) +wxALLOW_COMBINING_ENUMS(wxAlignment, wxSizerFlagBits) wxALLOW_COMBINING_ENUMS(wxAlignment, wxStretch) -wxALLOW_COMBINING_ENUMS(wxAlignment, wxBorder) -wxALLOW_COMBINING_ENUMS(wxDirection, wxStretch) +wxALLOW_COMBINING_ENUMS(wxBorder, wxDirection) +wxALLOW_COMBINING_ENUMS(wxBorder, wxGeometryCentre) +wxALLOW_COMBINING_ENUMS(wxBorder, wxSizerFlagBits) +wxALLOW_COMBINING_ENUMS(wxBorder, wxStretch) wxALLOW_COMBINING_ENUMS(wxDirection, wxGeometryCentre) +wxALLOW_COMBINING_ENUMS(wxDirection, wxStretch) +wxALLOW_COMBINING_ENUMS(wxDirection, wxSizerFlagBits) +wxALLOW_COMBINING_ENUMS(wxGeometryCentre, wxSizerFlagBits) +wxALLOW_COMBINING_ENUMS(wxGeometryCentre, wxStretch) +wxALLOW_COMBINING_ENUMS(wxSizerFlagBits, wxStretch) /* ---------------------------------------------------------------------------- */ /* Window style flags */ diff --git a/tests/sizers/boxsizer.cpp b/tests/sizers/boxsizer.cpp index 49e71a3c69..c566364284 100644 --- a/tests/sizers/boxsizer.cpp +++ b/tests/sizers/boxsizer.cpp @@ -447,3 +447,39 @@ TEST_CASE_METHOD(BoxSizerTestCase, "BoxSizer::Replace", "[sizer]") m_sizer->AddSpacer(1); m_sizer->Replace(0, new wxSizerItem(new wxWindow(m_win, wxID_ANY))); } + +TEST_CASE("Sizer::CombineFlags", "[sizer]") +{ + // This is a compile-time test which simply verifies that we can combine + // all the different flags without getting any warnings about doing it -- + // as would have been the case when using C++20 or later if we didn't use + // wxALLOW_COMBINING_ENUMS() for all these enums in wx/defs.h. + // + // These constants belong to the following enums, respectively: + // + // wxALIGN_CENTER wxAlignment + // wxBORDER_NONE wxBorder + // wxLEFT wxDirection + // wxCENTER wxGeometryCentre + // wxFIXED_MINSIZE wxSizerFlagBits + // wxEXPAND wxStretch + // + int n = (wxALIGN_CENTER | wxBORDER_NONE) + | (wxALIGN_CENTER | wxLEFT) + | (wxALIGN_CENTER | wxCENTER) + | (wxALIGN_CENTER | wxFIXED_MINSIZE) + | (wxALIGN_CENTER | wxEXPAND) + | (wxBORDER_NONE | wxLEFT) + | (wxBORDER_NONE | wxCENTER) + | (wxBORDER_NONE | wxFIXED_MINSIZE) + | (wxBORDER_NONE | wxEXPAND) + | (wxLEFT | wxCENTER) + | (wxLEFT | wxFIXED_MINSIZE) + | (wxLEFT | wxEXPAND) + | (wxCENTER | wxFIXED_MINSIZE) + | (wxCENTER | wxEXPAND) + | (wxFIXED_MINSIZE | wxEXPAND) + ; + + wxUnusedVar(n); +} From 4b0fa10a290d899278007f4743df3f811df506a1 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 31 Jul 2022 22:21:56 +0200 Subject: [PATCH 2/3] Don't mix flags from different enums in wxRegEx unit test Pass compilation and matching flags using separate parameters instead of passing them as a single int and then separating them inside the function. This is a bit cleaner and also avoids warning about using deprecated enum operations when using C++20. --- tests/regex/wxregextest.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/regex/wxregextest.cpp b/tests/regex/wxregextest.cpp index e1d58d1f65..291ed7afb1 100644 --- a/tests/regex/wxregextest.cpp +++ b/tests/regex/wxregextest.cpp @@ -71,12 +71,12 @@ static void CheckMatch(const char* pattern, const char* text, const char* expected = NULL, - int flags = wxRE_DEFAULT) + int compileFlags = wxRE_DEFAULT, + int matchFlags = 0) { - int compileFlags = flags & ~(wxRE_NOTBOL | wxRE_NOTEOL); - int matchFlags = flags & (wxRE_NOTBOL | wxRE_NOTEOL); - - INFO( "Pattern: " << pattern << FlagStr(flags) << ", match: " << text ); + INFO( "Pattern: " + << pattern << FlagStr(static_cast(compileFlags) | matchFlags) + << ", match: " << text ); wxRegEx re(pattern, compileFlags); if ( !re.IsValid() ) @@ -104,7 +104,7 @@ CheckMatch(const char* pattern, CHECK( re.GetMatch(text, i) == tkz.GetNextToken() ); } - if ((flags & wxRE_NOSUB) == 0) + if ((compileFlags & wxRE_NOSUB) == 0) CHECK(re.GetMatchCount() == i); } @@ -124,8 +124,8 @@ TEST_CASE("wxRegEx::Match", "[regex][match]") CheckMatch("^[A-Z].*$", "AA\nbb\nCC", "AA\nbb\nCC"); CheckMatch("^[A-Z].*$", "AA\nbb\nCC", "AA", wxRE_NEWLINE); CheckMatch("^[a-z].*$", "AA\nbb\nCC", "bb", wxRE_NEWLINE); - CheckMatch("^[A-Z].*$", "AA\nbb\nCC", "CC", wxRE_NEWLINE | wxRE_NOTBOL); - CheckMatch("^[A-Z].*$", "AA\nbb\nCC", NULL, wxRE_NEWLINE | wxRE_NOTBOL | wxRE_NOTEOL); + CheckMatch("^[A-Z].*$", "AA\nbb\nCC", "CC", wxRE_NEWLINE, wxRE_NOTBOL); + CheckMatch("^[A-Z].*$", "AA\nbb\nCC", NULL, wxRE_NEWLINE, wxRE_NOTBOL | wxRE_NOTEOL); CheckMatch("([[:alpha:]]+) ([[:alpha:]]+) ([[:digit:]]+).* ([[:digit:]]+)$", "Fri Jul 13 18:37:52 CEST 2001", "Fri Jul 13 18:37:52 CEST 2001\tFri\tJul\t13\t2001"); From e0dd7b852282b58d8ced0d05820f0526b01119a2 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 31 Jul 2022 21:12:12 +0200 Subject: [PATCH 3/3] Add a CI build using C++20 This should allow detecting C++20-specific problems, such as warnings about combining incompatible enums. --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7a5d8b9b0b..ab8bf3804f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -88,6 +88,10 @@ jobs: skip_samples: true use_asan: true use_xvfb: true + - name: Ubuntu 22.04 wxGTK C++20 + runner: ubuntu-22.04 + configure_flags: --with-cxx=20 + skip_samples: true - name: Ubuntu 18.04 wxX11 runner: ubuntu-18.04 configure_flags: --with-x11 --enable-pch --disable-stc