mirror of
https://github.com/ocornut/imgui.git
synced 2026-11-10 19:03:30 +00:00
Clang 11 warning: Bitwise operation between different enumeration types is deprecated #3040
Labels
No labels
accidentally closed
android
backends
bug
building
clipper
coloredit
color spaces
cplusplus
data types
demo
disabled
doc
docking
dpi
drag drop
drawing/drawlist
dropped
dx12
enhancement
focus
font/text
gallery
help wanted
idle/power saving
ime
in progress
inputs
inputtext
internals
label/id and id stack
language bindings
layout
linux/bsd
menus
multi-contexts
multi-threading
multi-viewports
nav
news/info
opengl
optimization
osx/ios
overlap
plot/graph
popups
question
scrolling
selection
settings
sliders/drags
style
tables/columns
tabs
test wanted
tools
tooltips
tree
tricks & tips
useful widgets
vulkan
web
window pos/depth
window sizing
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
ocornut/imgui#3040
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Dear ImGui version:
Branch:
898e91f20d(master at the time of writing)Back-end/Renderer/Compiler/OS
Back-end: custom Vulkan
Compiler: clang version 11.0.0-++20200123111717+04fd2041561-1~exp1
Operating System: Debian Unstable
My Issue/Question:
C++20's P1120R0 deprecated bitwise operations between different
enums. Such code is likely to become ill-formed in C++23.Clang 11 warns about such cases. There seems to be one case in ImGui. It should be fixed.
It could be related to #2685
Thank you for reporting! I'm disabling the warnings for now.
C++ commitee are becoming completely non-useful, C++ is just widely broken in term of allowing actual encapsulation of implementation details and it is getting worse. If they are going to obsolete this they should allow some form of enum inheritance.
Linking to #2993, #2995, will probably adopt some form of #2995 eventually meaning modern C++ is pushing us to be less type safe.
Commenting because although this is a couple of years old, it was the first hit in Google when I had the problem a few moments ago. My context was that Qt keycodes and modifiers (shift/alt/etc) are defined in different enums even though they are naturally designed to go together. Solution? One line:
inline constexpr int operator| (Qt::Modifier m, Qt::Key k) { return (int) m | (int) k; }(Yes, if you want to be pedantic, use static_cast() rather than (int), but I personally prefer to use C-style casts when the subtext is, "This is something that only needs to be done to satisfy pedantry")
On balance, though, I think this is a good thing. Mixing enums willy-nilly is not sensible, any more than adding physical units is - what are metres plus kilograms FFS?! - so requiring an explicit statement of when and how they can be combined is definitely a valuable guard against errors with negligible programmer effort.
Funny, got here with google search as well. On balance? Using enums for constant definition was always an established practice. If they care so much about mixing enums, why they do not limit that to e.g. named enums? Or just introduce some kind of enum that behaves like before.
This is not negligible effort - your solution is like 20% of what is needed. You would need to add reversed order operator|, then probably operator& too.
No, my solution was 100% of what I needed. It literally makes no sense to combine those two enum types in any other way, and I have no need to allow inconsistency in whether I write modifier|key or key|modifier. If you want enums that are nothing more than named ints, then use constexpr int or #define. I appreciate that it's a breaking change in the standard, but it's not one I'm unhappy about.
All in all, it feels like some useful feature was removed from the language for not really a good reason.
(Sorry ImGui for hijacking this debate...)
Indeed, but why do you want to be able to do that? I would suggest that in all but a few special cases, the point of enum is to create a set of names for a particular type of thing, and mixing different types of things without any constraint is a gateway to bugs.
I grant that in older C++, enum was used as a workaround for the absence of class constants, but now we have better ways, I have no problem with workarounds becoming deprecated.
At least half-serious. My point being that if you don't want constraints, use a mechanism that doesn't impose any :-)
I think we'll just have to agree to differ, and it's not removing a capability wholesale, it's just forcing you to be explicit if you really want to do it. Some other languages really don't let you do that kind of thing!
Basically the very same situation you have encountered with Qt. Set of keyboard constants. On some platforms, they have assigned values dictated by the platform. On others (e.g. virtual targets) it is not dictated by platform and values can be anything as long as they are different.
So my first intuitive fix for C++20 was to change everyhing to const int constants. Unfortunately broke compilation of virtual targets. And devising incremental values for like 200 contants is really boring with significant chance to introduce errors.
That said, I am thankful for your solution there, happilly adopted.. Still, I feel like C++20 forces me to fill the codebase with garbage like that (this is not only things that needed fixing).