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
Diagnose that std::unique_ptr::release is not allowed #70
Comments
Hi, thanks for taking the time to report your findings. I appreciate it! My proposal to go forward would be to improve our diagnostics, and directly say |
I'm not sure the C++ Core Guidelines explicitly ban Irrespective of the wording, I agree with having a specific diagnostic in this case. People may be confused between incorrect code (returning a pointer to a temporary) and prone to error code (like returning a pointer without explicit ownership). |
@mgehre would it be okay to extend the current LifetimeReporter for that kind of warning or should it better be handled by a new kind of Reporter ? |
We can use the LifetimeReporter and add a generic "this function disables lifetime analysis" warning in the existing "lifetime-disabled" category. |
The following piece of code causes a lifetime warning about returning a dangling pointer:
See in Godbolt: https://godbolt.org/z/fJyWl4
Is this correct? If we call
release
on aunique_ptr
, I'd assume that the unique pointer no longer retains ownership and a call to the destructor no longer destructs the pointed-toPrivateKey
object. I'd assume this is safe (not ideal because the caller would need to deletePrivateKey
manually, though, but the pointer should not dangle).The text was updated successfully, but these errors were encountered: