mirror of
https://github.com/ocornut/imgui.git
synced 2026-11-10 19:03:30 +00:00
signed flags cause clang-tidy warnings when using strict options #2993
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#2993
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?
Version/Branch of Dear ImGui:
Version: v1.75 WIP
Branch: master
Back-end/Renderer/Compiler/OS
Back-ends: imgui_impl_sdl2.cpp + imgui_impl_opengl3.cpp using gl3w
Compiler:
Operating System: void linux
My Issue/Question:
The underlying type of enums in c++ is implementation specific, but it usually ends up being int [1]. HIC++ reccomends against doing bit-ops on signed types and clang-tidy will complain when one does it anyways.
Now there is reason to argue that, on an end user application, having
-werrandhicpp-signed-bitwiseboth enabled on clang-tidy is a bit overkill, and i could just // NOLINT the few lines that will affect me, but i thought i bring it up anyway.Standalone, minimal, complete and verifiable example: (see https://github.com/ocornut/imgui/issues/2261)
becomes
I would suggest giving all enums an explicit type (unsigned int would be enough i think), but that would require c++11. I think some preprocessor-voodo could make sure it doesn't break when c++11 is not availble, but i do not know if something like that would be acceptable.
[1] https://timsong-cpp.github.io/cppwp/enum#dcl.enum-7
Hello,
Coincidentally we just ignored the equivalent MSVC warnings, also see https://github.com/ocornut/imgui/pull/2983#issuecomment-575623638
Short term we are going to ignore this as well within
imgui*.cppfiles, until we switch to C++11, but your code will have warnings.Hmm actually I got confused, if those are triggered by clang-tidy and not by clang, if there a way to disable them?
Does something like this works?
Near the top of each .cpp file?
clang-tidy runs separate from the normal compilation process, though cmake allows it to be run on each build (and builds fail if you then enable clang-tidys -werr flag).
The only way to ignore clang-tidy warnings is to either not enable them in the first place, or to silence a single line https://clang.llvm.org/extra/clang-tidy/#suppressing-undesired-diagnostics.
Ignoring it for now is what i expected, but i thought pointing it out anyway might not be the worst idea. Ill just disable (or, ugh, not enable) that specific warning for now.
Thanks for the reply!
Thanks for the clarification.
I actually have a patch to switch to unsigned int (since we use a different type for enum storage and value we can do it already). The main error I got was code in imgui_demo.cpp relying on one of the
RadioButton()overload to takeint*, and i switched to use the other variant already:ocornut/imgui@e499497ec5 (diff-fb4bd618fd)(I think that
int*RadioButton overload is a little bad design, may look into obsoleting it alltogether anyway)Test branch switching all flags to
unsigned intwith pre C++11:https://github.com/ocornut/imgui/tree/features/flags_unsigned_cpp03
Had to silent some warnings in imgui_demo.cpp otherwise most compilers are passing.
Then had to fix those warnings (See in Linux>Clang):
https://github.com/ocornut/imgui/runs/399795297
With
And it look quite silly/annoying, but I don't think it would often happen in user's codebase?
After the fix CI sees no warning:
https://github.com/ocornut/imgui/runs/399805362
I wouldn't mind committing that if I knew we have a safe later path to switch to C++11 for them, so probably going to try switching to that next.
Here with C++11 style
https://github.com/ocornut/imgui/tree/features/flags_unsigned_cpp11
CI:
https://github.com/ocornut/imgui/runs/399816469
Basically this:
Unfortunately this seems tricky as Clang and GCC include a warning as part of
-Wextraand can't seem to find how to disable it individually..It would require using e.g.
ImGuiWindowFlags_Nonebut that means a million breakage in user code including code copied from the demo.I'm on mobile right now, but I think to get rid of that you'd need to suppress
Wno-enum-compare(wich comes withWall?) and im not sure if that is a food idea.FWIW, the c++11 feature branch integrates just fine in my more recent projects and does not cause any warnings (and the clang-tidy thing i came here for is gone), but i do not do anything too weird in them.
Thinking about the warning issue - are the trailing-underscore enum types used by anyone, and is them being an enum strictly required?
They could probably become
constexpr unsigned inti think, as they are unscoped enums anyway.I tried that out, and
make -C examples/example_null EXTRA_WARNINGS=1now builds without warnings.The trailing underscore version mostly were created to workaround the inability to fwd declare enums pre C++11, without having to have all of them cluttering the top sections of imgui.h
You are right we could remove them. It would be useful to still have some way for IDEs to jump from the SomeFlags type right into the list of flags.
You are correct we could perhaps ditch enums as well and just use typedef, i am not acquainted enough with constexpr int in header to tell if they have any effect on what’s output from each compilation unit and passed to the linker.
Usage of constexpr values is, afaik, treated as literals as long no address is taken from the variable.
https://godbolt.org/z/Jw9wEk
However, symbols are still emitted as long as optimization is turned off.
Or, in the example_null case, using constexpr:
With a simple -O1 though:
I do not thing this would be a problem, as no one should be using them as anything else but replacement for writing literals/enums. I do not know how this effects compilation time or file size, but i suspect not that nicely, as long as .O0 is assumed.
Interestingly c++17 introduced inline constexpr variables to address this (those only ever emit one symbol and hence share an address, much like inline functions i suppose).