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
Warnings about freeing non-heap-allocated object #159
Comments
Very interesting. I don't think that code has changed. Maybe it's an improved analysis in gcc? I have Kubuntu 20.04 and don't see this. |
I think, the compiler does not understand the invariant that PS: I can see that there are places where you compare |
Can you help me reproduce this? I'm not very familiar with bjam. I always build Wave using
or from within
Neither of those commands seem to generate this warning - and I'm actually on Kubuntu 21.10 myself - though maybe I missed it. I don't seem to have a |
I'm on Kubuntu 22.04 now, and the command in the original post still produces the warnings with the current Boost develop. Replace
|
A simpler command that reproduces the warnings (also from Boost root):
(adjust |
Thanks! I can reproduce this now. I'm not sure what exactly to do; this code is actually the work of @andralex and is described in detail here. I've looked at it a bit and other than a pragma, I'm not sure how to safely make a change. The most recent version of the code from the master is here AFAICT and the |
The warnings are bogus because the pData_ pointer never points to emptyString_ if capacity() == 0, and always points otherwise. The compiler simply fails to deduce this invariant. Unfortunately, suppressing the warning with a #pragma doesn't work, so we have to invent a compile-time assert that will make the invariant detectable by the compiler. Closes boostorg#159.
* Use capacity() == 0 as the definitive mark of an empty string storage. Comparing the pointer with the static emptyString_ member of the SimpleStringStorage class will likely break if the comparison happens across shared library boundary. So use capacity() == 0 consistently to detect whether the storage refers to the emptyString_ member. When capacity is non-zero the data is always dynamically allocated. * Suppress gcc 11.2 -Wfree-nonheap-object warnings. The warnings are bogus because the pData_ pointer never points to emptyString_ if capacity() == 0, and always points otherwise. The compiler simply fails to deduce this invariant. Unfortunately, suppressing the warning with a #pragma doesn't work, so we have to invent a compile-time assert that will make the invariant detectable by the compiler. Closes #159. * Removed unused AllocatorStringStorage::Realloc function. This function was not used and potentially incorrect, as it unconditionally calls Free, which would be wrong if the original buffer was emptyString_.
On Kubuntu 21.10, gcc 11.2 produces warnings like these when building Boost.Wave 1.79.0 beta1 RC1 (presumably, revision f861b1a):
The command line is:
The text was updated successfully, but these errors were encountered: