News:

When registered with our forums, feel free to send a "here I am" post here to differ human beings from SPAM bots.

Main Menu

patch vs. compile-error wxPGFlags in trunk svn13676 with wxWidgets trunk

Started by blauzahn, July 17, 2025, 07:02:06 AM

Previous topic - Next topic

blauzahn

The implicit conversion of the enum is now disabled. I just added 2 static_cast instead.

--- trunk_20250716_vanilla/src/plugins/contrib/wxSmith/wxwidgets/properties/wxscolourproperty.cpp 2025-07-16 20:46:08.000000000 +0200
+++ trunk/src/plugins/contrib/wxSmith/wxwidgets/properties/wxscolourproperty.cpp 2025-07-16 21:39:08.141146237 +0200
@@ -205,7 +205,7 @@
         else
             cpv.Init( type, *wxWHITE );

-        m_flags |= wxPG_PROP_STATIC_CHOICES; // Colour selection cannot be changed.
+        m_flags |= static_cast<wxPGFlags>(wxPG_PROP_STATIC_CHOICES); // Colour selection cannot be changed.
         m_value << cpv;
         OnSetValue();
     }
@@ -583,7 +583,7 @@
             int index = paintdata.m_choiceItem;
             value = wxsColourValues[index];
         }
-        else if ( !(m_flags & (wxPGPropertyFlags)wxPG_PROP_UNSPECIFIED) )
+        else if ( !(m_flags & static_cast<wxPGFlags>(wxPG_PROP_UNSPECIFIED)) )
         {
             value = GetVal().m_type;
         }


I compiled it under Arch-Linux out-out-of tree using cmake, WX_PREFIX and --enable-pch=no as always.

Please feel free to correct trunk in a better way. Thank you for noticing this.

Miguel Gimenez

wxPGFlags was created 4 days ago, your patch would break compilation with all current wxWidgets' releases.

Can you try casting to FlagType instead, or removing the casts completely?

blauzahn

Unfortunately, simply casting to FlagType does not compile with wxWidgets trunk (3.3).

stahta01

C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

blauzahn

Yes. That does not compile either.

../../../../../../../trunk/src/plugins/contrib/wxSmith/wxwidgets/properties/wxscolourproperty.cpp: In member function 'void {anonymous}::wxsMyColourPropertyClass::Init(int, const wxColour&)':
../../../../../../../trunk/src/plugins/contrib/wxSmith/wxwidgets/properties/wxscolourproperty.cpp:209:17: error: no match for 'operator|=' (operand types are 'wxPGFlags' and 'const int')
  209 |         m_flags |= wxPG_PROP_STATIC_CHOICES; // Colour selection cannot be changed.
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
../../../../../../../trunk/src/plugins/contrib/wxSmith/wxwidgets/properties/wxscolourproperty.cpp:209:17: note: there is 1 candidate
In file included from /opt/wx/include/wx-3.3/wx/propgrid/propgrid.h:21,
                 from ../../../../../../../trunk/src/plugins/contrib/wxSmith/wxwidgets/properties/../../properties/wxsproperty.h:34,
                 from ../../../../../../../trunk/src/plugins/contrib/wxSmith/wxwidgets/properties/../../properties/wxsproperties.h:8,
                 from ../../../../../../../trunk/src/plugins/contrib/wxSmith/wxwidgets/properties/wxscolourproperty.h:28,
                 from ../../../../../../../trunk/src/plugins/contrib/wxSmith/wxwidgets/properties/wxscolourproperty.cpp:23:
/opt/wx/include/wx-3.3/wx/propgrid/property.h:423:18: note: candidate 1: 'wxPGFlags operator|=(wxPGFlags&, wxPGFlags)'
  423 | inline wxPGFlags operator|=(wxPGFlags & a, wxPGFlags b)
      |                  ^~~~~~~~
/opt/wx/include/wx-3.3/wx/propgrid/property.h:423:54: note: no known conversion for argument 2 from 'const int' to 'wxPGFlags'
  423 | inline wxPGFlags operator|=(wxPGFlags & a, wxPGFlags b)
      |                                            ~~~~~~~~~~^
../../../../../../../trunk/src/plugins/contrib/wxSmith/wxwidgets/properties/wxscolourproperty.cpp: In member function 'virtual void {anonymous}::wxsMyColourPropertyClass::OnCustomPaint(wxDC&, const wxRect&, wxPGPaintData&)':
../../../../../../../trunk/src/plugins/contrib/wxSmith/wxwidgets/properties/wxscolourproperty.cpp:587:29: error: no match for 'operator&' (operand types are 'wxPGFlags' and 'wxPG_EX_WINDOW_STYLES')
  587 |         else if ( !(m_flags & wxPG_PROP_UNSPECIFIED) )
      |                     ~~~~~~~ ^
      |                     |
      |                     wxPGFlags
../../../../../../../trunk/src/plugins/contrib/wxSmith/wxwidgets/properties/wxscolourproperty.cpp:587:29: note: there is 1 candidate
  587 |         else if ( !(m_flags & wxPG_PROP_UNSPECIFIED) )
/opt/wx/include/wx-3.3/wx/propgrid/property.h:428:21: note: candidate 1: 'constexpr wxPGFlags operator&(wxPGFlags, wxPGFlags)'
  428 | constexpr wxPGFlags operator&(wxPGFlags a, wxPGFlags b)
      |                     ^~~~~~~~
/opt/wx/include/wx-3.3/wx/propgrid/property.h:428:54: note: no known conversion for argument 2 from 'wxPG_EX_WINDOW_STYLES' to 'wxPGFlags'
  428 | constexpr wxPGFlags operator&(wxPGFlags a, wxPGFlags b)
      |                                            ~~~~~~~~~~^

Miguel Gimenez

Looks like wx3.3.1 is going out today, we can use wxCHECK_VERSION(3, 3, 1) if it includes the new wxPGFlags

EDIT: Do reinterpret_cast <FlagType>() or (FlagType) work?

blauzahn

I can try reinterpret_cast in the evening.

As for wxCHECK_VERSION: I usually try to minimize the use of macros and conditional compiling.

stahta01

Hand edited untested patch

--- trunk_20250716_vanilla/src/plugins/contrib/wxSmith/wxwidgets/properties/wxscolourproperty.cpp 2025-07-16 20:46:08.000000000 +0200
+++ trunk/src/plugins/contrib/wxSmith/wxwidgets/properties/wxscolourproperty.cpp 2025-07-16 21:39:08.141146237 +0200
@@ -205,7 +205,11 @@
         else
             cpv.Init( type, *wxWHITE );

+#if wxCHECK_VERSION(3, 1, 1)
+        m_flags |= static_cast<wxPGFlags>(wxPG_PROP_STATIC_CHOICES); // Colour selection cannot be changed.
+#else
         m_flags |= wxPG_PROP_STATIC_CHOICES; // Colour selection cannot be changed.
+#endif // wxCHECK_VERSION
         m_value << cpv;
         OnSetValue();
     }
@@ -583,7 +583,11 @@
             int index = paintdata.m_choiceItem;
             value = wxsColourValues[index];
         }
+#if wxCHECK_VERSION(3, 1, 1)
+        else if ( !(m_flags & static_cast<wxPGFlags>(wxPG_PROP_UNSPECIFIED)) )
+#else
         else if ( !(m_flags & (wxPGPropertyFlags)wxPG_PROP_UNSPECIFIED) )
+#endif // wxCHECK_VERSION
         {
             value = GetVal().m_type;
         }
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

Miguel Gimenez

In the new wx3.3.1 wxPGPropertyFlags still exists, as long as compatibility with 3.2 is enabled.

While Vadz recommends setting it to 0, the default (at least on MSW) is 1 and IMHO it should be this way for a while.

gd_on

I have compiled wxwidgets 3.3.1 with #define WXWIN_COMPATIBILITY_3_2 1, as it is still by default in wxWidgets' setup.h
Nevertheless, when buliding last svn C::B on Windows 11, I obtain compile errors in wxscolourproperty and the patch proposed by stahta01 solve these errors. Apparently, this setting to 3.2 compatibility is not sufficent.
Windows 11 64 bits (25H2), svn C::B (last version or almost!), wxWidgets 3.3.2, Msys2 Compilers 16.1.0, 64 bits (seh, posix : gcc, g++ and gfortran in C:\msys64\mingw64) or 32 bits (dwarf2, posix  in C:\msys64\mingw32).

Miguel Gimenez

Quote#if wxCHECK_VERSION(3, 1, 1)
QuoteI have compiled wxwidgets 3.1.1

I hope both statements are wrong  :P , they should be 3.3.1.

Blauzahn will test with reinterpret_cast <FlagType> () or (FlagType) this evening.
gd_on, probably you can do it now.

EDIT: I have not compiled C::B with 3.3.1 yet, but all the wxWidgets samples crash on closing (tested with W7, 32 bits and monolithic DLL). If C::B compiled with wx3.3.1 crashes on closing may be due to this issue.

gd_on

You are right. I should have written 3.3.1. I have corrected my previous post.
And of course, the patch should be with :

#if wxCHECK_VERSION(3, 3, 1)


Tested and looks OK
Windows 11 64 bits (25H2), svn C::B (last version or almost!), wxWidgets 3.3.2, Msys2 Compilers 16.1.0, 64 bits (seh, posix : gcc, g++ and gfortran in C:\msys64\mingw64) or 32 bits (dwarf2, posix  in C:\msys64\mingw32).

Miguel Gimenez

Can you check with reinterpret_cast <FlagType> ()?

Thank you.

blauzahn

reinterpret_cast also does not compile as I suspected.


../../../../../../../trunk/src/plugins/contrib/wxSmith/wxwidgets/properties/wxscolourproperty.cpp: In member function 'void {anonymous}::wxsMyColourPropertyClass::Init(int, const wxColour&)':
../../../../../../../trunk/src/plugins/contrib/wxSmith/wxwidgets/properties/wxscolourproperty.cpp:210:37: warning: 'wxPGProperty::FlagType' is deprecated: use wxPGFlags type instead [-Wdeprecated-declarations]
  210 |         m_flags |= reinterpret_cast<FlagType>(wxPG_PROP_STATIC_CHOICES); // Colour selection cannot be changed.
      |                                     ^~~~~~~~
In file included from /opt/wx/include/wx-3.3/wx/propgrid/propgrid.h:21,
                 from ../../../../../../../trunk/src/plugins/contrib/wxSmith/wxwidgets/properties/../../properties/wxsproperty.h:34,
                 from ../../../../../../../trunk/src/plugins/contrib/wxSmith/wxwidgets/properties/../../properties/wxsproperties.h:8,
                 from ../../../../../../../trunk/src/plugins/contrib/wxSmith/wxwidgets/properties/wxscolourproperty.h:28,
                 from ../../../../../../../trunk/src/plugins/contrib/wxSmith/wxwidgets/properties/wxscolourproperty.cpp:23:
/opt/wx/include/wx-3.3/wx/propgrid/property.h:1038:22: note: declared here
1038 |     typedef wxUint32 FlagType;
      |                      ^~~~~~~~
../../../../../../../trunk/src/plugins/contrib/wxSmith/wxwidgets/properties/wxscolourproperty.cpp:210:20: error: invalid cast from type 'int' to type 'wxPGProperty::FlagType' {aka 'unsigned int'}
  210 |         m_flags |= reinterpret_cast<FlagType>(wxPG_PROP_STATIC_CHOICES); // Colour selection cannot be changed.
      |                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../../../../../../trunk/src/plugins/contrib/wxSmith/wxwidgets/properties/wxscolourproperty.cpp:211:37: warning: 'wxPGProperty::FlagType' is deprecated: use wxPGFlags type instead [-Wdeprecated-declarations]
  211 |         m_flags |= reinterpret_cast<FlagType>(wxPG_PROP_STATIC_CHOICES); // Colour selection cannot be changed.
      |                                     ^~~~~~~~
/opt/wx/include/wx-3.3/wx/propgrid/property.h:1038:22: note: declared here
1038 |     typedef wxUint32 FlagType;
      |                      ^~~~~~~~
../../../../../../../trunk/src/plugins/contrib/wxSmith/wxwidgets/properties/wxscolourproperty.cpp:211:20: error: invalid cast from type 'int' to type 'wxPGProperty::FlagType' {aka 'unsigned int'}
  211 |         m_flags |= reinterpret_cast<FlagType>(wxPG_PROP_STATIC_CHOICES); // Colour selection cannot be changed.
      |                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../../../../../../trunk/src/plugins/contrib/wxSmith/wxwidgets/properties/wxscolourproperty.cpp: In member function 'virtual void {anonymous}::wxsMyColourPropertyClass::OnCustomPaint(wxDC&, const wxRect&, wxPGPaintData&)':
../../../../../../../trunk/src/plugins/contrib/wxSmith/wxwidgets/properties/wxscolourproperty.cpp:589:48: warning: 'wxPGProperty::FlagType' is deprecated: use wxPGFlags type instead [-Wdeprecated-declarations]
  589 |         else if ( !(m_flags & reinterpret_cast<FlagType>(wxPG_PROP_UNSPECIFIED)) )
      |                                                ^~~~~~~~
/opt/wx/include/wx-3.3/wx/propgrid/property.h:1038:22: note: declared here
1038 |     typedef wxUint32 FlagType;
      |                      ^~~~~~~~
../../../../../../../trunk/src/plugins/contrib/wxSmith/wxwidgets/properties/wxscolourproperty.cpp:589:31: error: invalid cast from type 'wxPG_EX_WINDOW_STYLES' to type 'wxPGProperty::FlagType' {aka 'unsigned int'}
  589 |         else if ( !(m_flags & reinterpret_cast<FlagType>(wxPG_PROP_UNSPECIFIED)) )
      |                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../../../../../../trunk/src/plugins/contrib/wxSmith/wxwidgets/properties/wxscolourproperty.cpp: In member function 'virtual bool {anonymous}::wxsMyColourPropertyClass::StringToValue(wxVariant&, const wxString&, int) const':
../../../../../../../trunk/src/plugins/contrib/wxSmith/wxwidgets/properties/wxscolourproperty.cpp:674:57: warning: 'virtual bool wxEnumProperty::StringToValue(wxVariant&, const wxString&, int) const' is deprecated: use StringToValue with 'flags' argument as wxPGPropValFormatFlags [-Wdeprecated-declarations]
  674 |                 bool res = wxEnumProperty::StringToValue(value, colourName, argFlags);
      |                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /opt/wx/include/wx-3.3/wx/propgrid/propgrid.h:2210:
/opt/wx/include/wx-3.3/wx/propgrid/props.h:519:18: note: declared here
  519 |     virtual bool StringToValue(wxVariant& variant, const wxString& text,
      |                  ^~~~~~~~~~~~~
make[7]: *** [Makefile:677: wxscolourproperty.lo] Fehler 1


wxCHECK_VERSION seems to be used quite often in cb. Where do I find the minimum required version? Can't find it at first glance.
In case it is wxCHECK_VERSION(3, 0, 0) anyway, shouldn't those conditionals be updated, that is eliminated? I also like backwards
compatibility for some not too short time. That allows to update dependent projects like cb on their own pace and stepwise instead of
a big bang. Nice if indicated by [[deprecated]] and tools like clang-tidy [-modernize-...].

Thanks for the active contributions.


Miguel Gimenez

We support wx3.0.x because it is the version included in some Linux distributions still in use (p.e. Mint 18 or Ubuntu 22.04).

Fixed in r13679, thank you.