-
-
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
Silence false-positive warning for malformed placement new on GCC 11.1 #52123
Silence false-positive warning for malformed placement new on GCC 11.1 #52123
Conversation
I did quite a bit of research on why this warning pops up here. More specifically, it's because GCC thinks that GCC doesn't know though (and cannot know, because the allocation is dynamic) that in this case, the pointer returned by Assigning to a new variable fools the check, because the compiler thinks that this is the beginning of a separate array, and no such subtraction is done. Therefore, the warning seems to be a false positive logic-wise, but is valid because it's not immediately clear to an outside observer that the subtraction is OK. I propose that we stay with the variables along with a comment, as they both satisfy GCC and make it clear that the subtraction is fine and done for a purpose. Any better ideas welcome. @Calinou @godotengine/core ? |
e02a094
to
f25ccc7
Compare
f25ccc7
to
be887bf
Compare
be887bf
to
fde8532
Compare
@godotengine/core ? |
fde8532
to
a4d01a9
Compare
@nathanfranke please let me know if I changed this correctly |
Yes, looks fine. Although maybe another core contributor can look at it, since I think there are some exceptions or issues that can arise from using references. |
Considering that the reason for those interim pointers will most likely be no apparent to a future reader of that code, I'd suggest adding a comment about their purpose. However, if we take into account the size of the base patch plus comments and also that the goal is to silence a really broken warning, I'd suggest going with this:
Anyone expected to maintain this file will know how to understand it. |
a4d01a9
to
fa25d0e
Compare
@RandomShaper done |
8bb4e4e
to
83a3be0
Compare
Might be worth amending the commit title as we're no longer fixing the warning but silencing it as a false positive. |
On latest (11.1 as of this commit) GCC, the following warning is continuously issued during build: warning: placement new constructing an object of type 'SafeNumeric<unsigned int>' and size '4' in a region of type 'uint32_t*' {aka 'unsigned int*'} and size '0' [-Wplacement-new=] This happens because on 98ceb60 the new operator override used was dropped and replaced with standard placement new. GCC sees the subtraction from the pointer and complains as it thinks that the SafeNumeric is placed outside an allocation, not knowing that the address requested is already inside one. After suggestions, the false positive is silenced, with no other changes.
83a3be0
to
abef2b7
Compare
@akien-mga done and done |
Thanks! |
This closes #52119. Right now I am moving the offset to its own variable in order to calm down GCC's warning. Better ideas always welcome.