Skip to content
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

I.12 not_null has converting constructors? #767

Closed
akrzemi1 opened this issue Oct 11, 2016 · 2 comments
Closed

I.12 not_null has converting constructors? #767

akrzemi1 opened this issue Oct 11, 2016 · 2 comments

Comments

@akrzemi1
Copy link
Contributor

It might be more about GSL than this project. It seems to me that offering a conversion from T to not_null looses the potential to detect certain bugs at compile-time.

if I have a function that returns a raw (potentially null) pointer, and I carelessly pass it to a function taking not_null it will compile fine, and will try report a bug at run-time when it is likely too late.

Instead, if the constructor from T were explicit, an inadvertent assignment:

use_ptr(make_ptr());

would be impossible, and I would be forced to explicitly require a potentially unsafe conversion:

use_ptr(not_null<T>{make_ptr()});

This would be a kind of the signature: by writing this cast, I am taking the responsibility for guaranteeing that the raw pointer will not be null. If it is not the case, you will know that I did it consciously.

@akrzemi1
Copy link
Contributor Author

I really consider this converting constructor a safety issue.

@AndrewPardoe
Copy link
Contributor

Thank you for moving this issue to the GSL repo. Closing this as a stale issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants