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

no conversion from T to not_null<T> #401

Closed
wants to merge 2 commits into from

Conversation

akrzemi1
Copy link

No description provided.

@msftclas
Copy link

Hi @akrzemi1, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!

In order for us to evaluate and accept your PR, we ask that you sign a contribution license agreement. It's all electronic and will take just minutes. I promise there's no faxing. https://cla.microsoft.com.

TTYL, MSBOT;

CHECK((void*)p.get() == (void*)t.get());
}

TEST(TestNotNullAssignment)
{
int i = 12;
not_null<int*> p = &i;
not_null<int*> p(&i);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are getting rid of the assignment operator of T, do we need the test at all? I believe there are already tests for construction.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That line isn't exercising assignment though.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a make_not_null factory ?

void f(not_null<int*>);
f(make_not_null(&i))

Wondering if in the particular case of not_null<T*> it couldn't be copy-constructed and assigned from a T&.

f(i); // implicit conversion from T& to `not_null<T*>`

Copy link
Collaborator

@neilmacintosh neilmacintosh Oct 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@viboes actually, there's already some discussion (and previous code intent) to allow exactly that. See #396 for a recent post on the topic.

[Edit] Sorry to be clear, I meant on the topic of constructing from a T&. I like the idea of a make_not_null() factory function. The only reason I didn't originally add one is that I was nervous it would confuse people as to whether it allocated given the prior art of make_shared and make_unique

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@neilmacintosh make_not_null() is not a good idea, but what about gsl::addressof() just like the one in std?

@annagrin
Copy link

please see discussion in #699. Closiing this since we decided to remove the explicit constructor and add strict_not_null type for practical purposes.

@annagrin annagrin closed this Jan 17, 2019
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

Successfully merging this pull request may close these issues.

9 participants