-
Notifications
You must be signed in to change notification settings - Fork 403
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
Easy misuse in cxx::unique_ptr
#1655
Comments
@elfenpiff I never understood why |
@elfenpiff @mossmaurice having the deleter as part of the // pseudocode
UntypedSubscriber s1;
UntypedSubscriber s2;
auto sample = unique_ptr<T>(static_cast<T*> s1.take(), [&](ptr) { s1.release(); });
sample.reset(static_cast<T*> s2.take()); To make this safe, the reset method must require a deleter. |
…nique_ptr Signed-off-by: Simon Hoinkis <[email protected]>
…nique_ptr Signed-off-by: Simon Hoinkis <[email protected]>
…nique_ptr Signed-off-by: Simon Hoinkis <[email protected]>
…xx::unique_ptr' Signed-off-by: Simon Hoinkis <[email protected]>
…nique_ptr Signed-off-by: Simon Hoinkis <[email protected]>
…xx::unique_ptr' Signed-off-by: Simon Hoinkis <[email protected]>
…'cxx::unique_ptr' Signed-off-by: Simon Hoinkis <[email protected]>
Signed-off-by: Simon Hoinkis <[email protected]>
…xx::unique_ptr' Signed-off-by: Simon Hoinkis <[email protected]>
Signed-off-by: Simon Hoinkis <[email protected]>
…xx::unique_ptr' Signed-off-by: Simon Hoinkis <[email protected]>
Signed-off-by: Simon Hoinkis <[email protected]>
…xx::unique_ptr' Signed-off-by: Simon Hoinkis <[email protected]>
Required information
Since the deleter is part of the constructor argument but otherwise unchangeable it is extremely hard to track which deleter is currently in use.
Do you spot the bug:
The deleter changes silently when
b
is moved toa
but the user may assumes thata
is still a unique_ptr which calls delete on destruction. This can be mixed up extremely easily!The solution would be to make the deleter part of the
unique_ptr
type like the STL does. The deleter would be a callable type which releases the underlying resource and would look like:The text was updated successfully, but these errors were encountered: