-
Notifications
You must be signed in to change notification settings - Fork 164
Removed potentially-misleading dead code and comment #36
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
Since ptr is being passed by value to the lambda expression, setting ptr to null will have no effect past that single line. The combination of the code and the comment which implies there is an additional benefit/security in doing so might mislead a maintainer or developer down the road.
Removed potentially-misleading dead code and comment
|
Thanks for your contribution 👍 |
|
Hey i want my nullptr back! ;) |
|
@aminroosta Cheers. @Killili yes, but the pointer is being passed by value, not by reference. As in, the ptr you are nulling here is only nulled in this scope and not anywhere else. I suppose you could change it to |
|
I think |
|
@Killili do you think |
|
@aminroosta Just in case it looked like I was endorsing that option - I wasn't. Just pointing out what the code would have had to look like in order to match the intent described in the (now deleted) comment. |
|
There was something about referencing lambdas as custom deleters and "why thats bad". Thats why its a [=]{} lambda. |
|
Thats so typical , I write one comment and someone finds that something is wrong with it ;) @mqudsi youre right about it not making any difference but it had a purpose and i think we should have it. Because the people using the shared_ptr outside of our class will use it in its naked untracked form as in some_function( ptr.get() , ...) and maybe dont realize that when they go out of scope of the shared_ptr. |
|
@Killili I'm not sure I understand; I'm a little confused. The code that was there had no effect and did not change the value of |
|
@mqudsi As i said you where right. It did nothing there in its last version but i had it there intentionally to do something that i think is worth having. And now i'm trying to get it actually working in the why it was intended. |
|
@Killili thanks, that makes sense. |
|
When a user uses So even if we set the actual shared_ptr to nullptr it won't help either. @Killili I think if it makes a difference while debugging in visual studio, then it won't hurt to have it back. |
|
@aminroosta no the code will still do nothing as @mqudsi explained and the difference in debug behavior is due to shared_ptr nulling itself on destruction in debug but saving this op at runtime (at least in VC last time i checked). |
|
I think we can all live with an extra comment :-) |
|
Nice but this actually makes it worse ;) |
|
Why? Is that sarcastic :-) |
|
Now we have a comment saying that this line does nothing and it does not even do the thing it is supposed to help with... |
|
@Killili which one? do think is the better approach. |
|
Ok i tested a few scenarios and we can't possibly follow the copy's of the naked pointer. So i think we should just drop the thing and call it a day. The line should just be: _db = std::shared_ptr<sqlite3>(tmp, [=](sqlite3* ptr) { sqlite3_close_v2(ptr); }); // this will close the connection eventually when not longer needed, and can not solve world hunger in the process! |
|
1- will do absolutely nothing |
|
@Killili i agree. |
Since ptr is being passed by value to the lambda expression,
setting ptr to null will have no effect past that single line.
The combination of the code and the comment which implies there
is an additional benefit/security in doing so might mislead a
maintainer or developer down the road.