-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Make it possible to overwrite debug macros locally. #5183
Conversation
Leaking macros across headers is a terrible thing, but I can't think of a better way of achieving this. - We need some way of modifying debug macros from CMake to implement ENABLE_ALL_THE_DEBUG_MACROS. - We need some way of modifying debug macros in specific source files because otherwise we need to rebuild too many files. This was done using the following script: sed -i -E 's/#cmakedefine01 ([A-Z0-9_]+)/#ifndef \1\n\0\n#endif\n/' AK/Debug.h.in sed -i -E 's/#cmakedefine01 ([A-Z0-9_]+)/#ifndef \1\n\0\n#endif\n/' Kernel/Debug.h.in
Hmm, I don't think ENABLE_ALL_THE_DEBUG_MACROS is actually needed anymore. |
The problem is that template code inside of #include <type_traits>
template<typename T>
void bar() {
static_assert(std::is_same<T, void>::value);
}
void foo() {
if constexpr (false) {
// This will cause the static assertion in bar() to fail, but we don't get an
// error because it's not evaluated for some reason.
bar<int>();
}
} If the In other words, code rot is possible with this new approach too. It might be possible to use a runtime Also, there are still a few cases left where This might just be a compiler bug though, so maybe I should check in the standard if the compiler actually behaves correctly here. (I am a bit scared of doing that, but maybe I'll spend an hour or two tomorrow and try to make sense of this.) |
I think the whole point of |
Uh, that's a good point. So this doesn't actually cover bitrot beyond basic parsing I guess. :/ |
I've tried actually looking in the standard but was only able to find this in N4868:
I couldn't really find any proper definition of a "discarded statement", but this really sounds like the compiler is behaving correctly here. |
This should solve the compile-time problem when toggling debug options. #5104 (comment)
Now, it is possible to locally overwrite debug macros by defining them before including
AK/Debug.h
orKernel/Debug.h
:The problem with this approach is that the locally defined macro always has precedence:
This is why I held this back for a while, but I can't think of a better way.
In theory I could solve this by changing
AK/Debug.h
to something like this:But that's pretty spam-y and in some situations it might be helpful to disable debugging in one source file.