-
-
Notifications
You must be signed in to change notification settings - Fork 22.8k
Fix MSVC warning for potential mod by 0 (C4724) #106634
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
Conversation
I'm adding static casts to |
|
Sorry, I didn't read the return type closely enough. I'm used to container size types always being unsigned e.g. Either way, the original usage of |
We don't usually use explicit static casts in such cases. Our consensus is that it makes code harder to read and doesn't add much value. |
Should I remove the casts or just leave them? |
I would just use |
Looks good! Could you squash the commits? See PR workflow for instructions. |
Thanks! And congrats for your first merged Godot contribution 🎉 |
So the strange thing is, now my Godot 4.4.1-stable builds are failing with that exact error, |
Most likely the GitHub Actions runner for Windows was updated to a newer version of MSVC which triggers this warning. @nukethebees might have been running a preview or just a more up-to-date version than GHA a month ago. |
There were conflicts when backporting this to Godot 4.3, so I opened PR #108321 to manually backport it. However, this PR can be automatically cherry-picked for Godot 4.4. |
With
dev_mode=yes
, MSVC warns that some modulo expressions may bex % 0
and refuses to compile.By assigning the size variables to local variables, the compiler knows
size > 0
if the loop bodies are entered. Without the local variable, it's technically possible forsize()
to become zero after entering the body.https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4724?view=msvc-170