-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
signed flags cause clang-tidy warnings when using strict options #2993
Comments
Hello, Coincidentally we just ignored the equivalent MSVC warnings, also see #2983 (comment) Short term we are going to ignore this as well within |
Hmm actually I got confused, if those are triggered by clang-tidy and not by clang, if there a way to disable them?
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 (I think that Test branch switching all flags to Had to silent some warnings in imgui_demo.cpp otherwise most compilers are passing.
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: 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 Basically this:
Unfortunately this seems tricky as Clang and GCC include a warning as part of |
I'm on mobile right now, but I think to get rid of that you'd need to suppress |
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? |
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. 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). |
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
-werr
andhicpp-signed-bitwise
both 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 #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
The text was updated successfully, but these errors were encountered: