-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
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
[3.x] Fix #if *_ENABLED
inconsistencies, should check if defined
#87272
Conversation
Please squash your commits into one, see here |
6886342
to
0e7c853
Compare
We don't do that for various reasons, it's part of the workflow 🙂, see that link, we don't squash commits because it:
We're well aware of this feature and there's very good reasons we don't use it, and it's not much work, and it saves maintainers work who have to merge each PR |
It's squashed. Do you need anything else? |
No it looks good otherwise 🙂 |
I didn't write this, but a quick test in godbolt suggests in the existing format: If e.g. If it is undefined, the compiler will flag an error:
So by adding the So this may need a little double checking if to be changed. The existing code is valid c++, but just open to mis-interpretation (and could indeed be a copy pasta error). Afaik the I have limited time to check this, but just wanted to flag this and make sure it had been tested. Pinging @clayjohn as at least some of this is his code (although it may be copy pasted for the #elif). |
There's a difference between passing a define on the command line with Notably, this also applies to names which have not been defined on the command line. If That's why this code "works" e.g. on Android where only Test script to confirm that: // Compile with: g++ main.cpp -DD -DE=1 -DF=0
#include <cstdio>
#define A
#define B 1
#define C 0
// D passed on command line with -DD
// E passed on command line with -DE=1
// F passed on command line with -DF=0
// no G
#define _STR(m_x) #m_x
#define _MKSTR(m_x) _STR(m_x)
int main() {
printf("A: %s\n", _MKSTR(A));
printf("B: %s\n", _MKSTR(B));
printf("C: %s\n", _MKSTR(C));
printf("D: %s\n", _MKSTR(D));
printf("E: %s\n", _MKSTR(E));
printf("F: %s\n", _MKSTR(F));
printf("G: %s\n", _MKSTR(G));
/*
// Fails with: error: #if with no expression
#if A
printf("A is true.\n");
#endif
*/
#if B
printf("B is true.\n");
#endif
#if C
printf("C is true.\n");
#endif
#if D
printf("D is true.\n");
#endif
#if E
printf("E is true.\n");
#endif
#if F
printf("F is true.\n");
#endif
#if G
printf("G is true.\n");
#endif
return 0;
} Prints:
All Numbers in the codebase speak for themselves (
For that last one it's 7 occurrences in the |
#if *_ENABLED
inconsistencies, should check if defined
This PR should likely also assess the cases where And this all needs to be done for the I'll make a |
I amended the commit with the
Done: #87286. |
Co-authored-by: Rémi Verschelde <rverschelde@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be good to go.
Also included the minor style fix from #87271 in this PR as it's also just fixing a pre-processor macro inconsistency.
Thanks! And congrats for your first merged Godot contribution 🎉 |
As discussed on RocketChat, these checks are probably written incorrectly.