NotNull's comment incorrectly claims that NotNull<UniquePtr<T>> "doesn't work"
Categories
(Core :: MFBT, defect)
Tracking
()
People
(Reporter: mozbugz, Assigned: sg)
References
Details
Attachments
(1 file)
(deleted),
text/x-phabricator-request
|
Details |
Reporter | ||
Comment 1•7 years ago
|
||
Reporter | ||
Comment 2•7 years ago
|
||
Comment 3•7 years ago
|
||
Comment 4•7 years ago
|
||
Reporter | ||
Comment 5•5 years ago
|
||
Just discussed about NotNull and UniquePtr, this made me find this old bug! 😄
Some extra thoughts:
And I also found I actually tested NotNull<UniquePtr<>>
there:
https://searchfox.org/mozilla-central/rev/597a69c70a5cce6f42f159eb54ad1ef6745f5432/mfbt/tests/TestNotNull.cpp#336
But it's a bare test, I think more needs to be done to officially support NotNull<UniquePtr<>>
.
In particular, how to deal with moving from a NotNull<UniquePtr<>>
? Because it's a unique pointer, we need to reset the moved-from object to null, which would break the NotNull
invariant. But then a moved-from object should not be used anymore, except to destroy it and maybe re-assign it.
At the moment I'm thinking that NotNull<UniquePtr<>>
may need a specialization, or some extra asserts, to make sure that a moved-from object (that contains a nullptr) is not queried until destruction or re-assignment.
A specialization could redefine get()
to return a NotNull<>
.
And what about UniquePtr<NotNull<>>
, is that possible, and should it behave the same way?
Assignee | ||
Comment 6•4 years ago
|
||
Bug 1634003 added some things to make this more usable, in particular a MovingNotNull
class template, and it actually added a test with UniquePtr
: https://searchfox.org/mozilla-central/rev/8d722de75886d6bffc116772a1db8854e34ee6a7/mfbt/tests/TestNotNull.cpp#360-377
But the comment is still there, and should be removed.
I am not sure if this addresses all your concerns/questions?
And what about UniquePtr<NotNull<>>, is that possible,
I guess it's possible as there are no particular constraints on the pointee type of a UniquePtr
, but is that useful?
and should it behave the same way?
I guess not. It would be a possible null unique pointer to a non-null pointer...
Reporter | ||
Comment 7•4 years ago
|
||
Sorry, I didn't notice the NI until now.
Yes, bug 1634003 helps, thank you.
I can't remember the exact problem with UniquePtr<NotNull<...>>
though, it now feels like it "should just work", but it's probably not very useful anyway -- I guess it could happen through some generic code.
Anyway, happy for this bug to focus again on fixing the old comment.
Assignee | ||
Comment 8•4 years ago
|
||
Updated•4 years ago
|
Assignee | ||
Updated•4 years ago
|
Comment 10•4 years ago
|
||
bugherder |
Updated•4 years ago
|
Description
•