raysan5 / raygui

A simple and easy-to-use immediate-mode gui library
zlib License
3.53k stars 302 forks source link

Prevent conditional expression between different enum types using `static_cast` #426

Closed Adrian-Samoticha closed 1 month ago

Adrian-Samoticha commented 1 month ago

I get the following error when compiling with -std=gnu++20:

src/raygui.h:2089:41: warning: conditional expression between different enumeration types ('GuiControlProperty' and 'GuiDefaultProperty') is deprecated [-Wdeprecated-enum-compare-conditional]
                                        ? BORDER_COLOR_DISABLED
                                        ^ ~~~~~~~~~~~~~~~~~~~~~
src/raygui.h:2096:41: warning: conditional expression between different enumeration types ('GuiControlProperty' and 'GuiDefaultProperty') is deprecated [-Wdeprecated-enum-compare-conditional]
                                        ? BORDER_COLOR_DISABLED
                                        ^ ~~~~~~~~~~~~~~~~~~~~~
src/raygui.h:2103:41: warning: conditional expression between different enumeration types ('GuiControlProperty' and 'GuiDefaultProperty') is deprecated [-Wdeprecated-enum-compare-conditional]
                                        ? BORDER_COLOR_DISABLED
                                        ^ ~~~~~~~~~~~~~~~~~~~~~
src/raygui.h:2129:42: warning: conditional expression between different enumeration types ('GuiControlProperty' and 'GuiDefaultProperty') is deprecated [-Wdeprecated-enum-compare-conditional]
      DEFAULT, (state == STATE_DISABLED) ? BORDER_COLOR_DISABLED : LINE_COLOR));
                                         ^ ~~~~~~~~~~~~~~~~~~~~~   ~~~~~~~~~~
src/raygui.h:2194:54: warning: conditional expression between different enumeration types ('GuiControlProperty' and 'GuiDefaultProperty') is deprecated [-Wdeprecated-enum-compare-conditional]
                                                     ? BORDER_COLOR_DISABLED
                                                     ^ ~~~~~~~~~~~~~~~~~~~~~
src/raygui.h:2197:54: warning: conditional expression between different enumeration types ('GuiControlProperty' and 'GuiDefaultProperty') is deprecated [-Wdeprecated-enum-compare-conditional]
                                                     ? BASE_COLOR_DISABLED
                                                     ^ ~~~~~~~~~~~~~~~~~~~

Since conditional expressions between different enum types are now deprecated in C++20, perhaps static_cast should be used to cast one enum type into the other one first?

Note: Please disregard the line numbers as I am using an outdated verson of raygui (which I may have accidentally formatted). In the latest version on the master branch (commit 6aae838), the line numbers should be 1642 and onwards.

raysan5 commented 1 month ago

@Adrian-Samoticha I'm afraid raygui is C, not C++ and static_cast does not exist in C, maybe it can be addressed with a regular cast, feelf ree to send a PR with the fix.

Adrian-Samoticha commented 1 month ago

@raysan5 You’re right, I somehow missed that. And indeed, a regular cast does indeed fix the issue. I’ll send the PR soon.