зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1631709
- NotNull must not be movable. r=jwalden
Differential Revision: https://phabricator.services.mozilla.com/D71721
This commit is contained in:
Родитель
c909a79d87
Коммит
8f84ea1eaa
|
@ -144,6 +144,13 @@ class NotNull {
|
|||
return mBasePtr.operator->();
|
||||
}
|
||||
constexpr decltype(*mBasePtr) operator*() const { return *mBasePtr; }
|
||||
|
||||
// NotNull can be copied, but not moved. Moving a NotNull with a smart base
|
||||
// pointer would leave a nullptr NotNull behind. The move operations must not
|
||||
// be explicitly deleted though, since that would cause overload resolution to
|
||||
// fail in situations where a copy is possible.
|
||||
NotNull(const NotNull&) = default;
|
||||
NotNull& operator=(const NotNull&) = default;
|
||||
};
|
||||
|
||||
// Specialization for T* to allow adding MOZ_NONNULL_RETURN attributes.
|
||||
|
|
|
@ -288,6 +288,14 @@ void TestNotNullWithRefPtr() {
|
|||
|
||||
// At this point the refcount is 4.
|
||||
|
||||
NotNull<RefPtr<MyRefType>> r6 = std::move(r2);
|
||||
mozilla::Unused << r6;
|
||||
|
||||
CHECK(r2.get());
|
||||
CHECK(r6.get());
|
||||
|
||||
// At this point the refcount is 5 again, since NotNull is not movable.
|
||||
|
||||
// At function's end all RefPtrs are destroyed and the refcount drops to 0
|
||||
// and the MyRefType is destroyed.
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче