Bug 1628715 - Part 12: Add WrapNotNullUnchecked for NotNull<T*>. r=xpcom-reviewers,nika,jwalden

Differential Revision: https://phabricator.services.mozilla.com/D71296
This commit is contained in:
Simon Giesecke 2020-04-24 13:33:35 +00:00
Родитель b48c0c7970
Коммит 1961cd994a
1 изменённых файлов: 21 добавлений и 0 удалений

Просмотреть файл

@ -106,6 +106,8 @@ template <typename T>
class NotNull {
template <typename U>
friend constexpr NotNull<U> WrapNotNull(U aBasePtr);
template <typename U>
friend constexpr NotNull<U*> WrapNotNullUnsafe(U* aBasePtr);
template <typename U, typename... Args>
friend constexpr NotNull<U> MakeNotNull(Args&&... aArgs);
@ -157,6 +159,25 @@ constexpr NotNull<T> WrapNotNull(const T aBasePtr) {
return notNull;
}
// WrapNotNullUnchecked should only be used in situations, where it is
// statically known that aBasePtr is non-null, and redundant release assertions
// should be avoided. It is only defined for raw base pointers, since it is only
// needed for those right now. There is no fundamental reason not to allow
// arbitrary base pointers here.
template <typename T>
MOZ_NONNULL(1)
constexpr NotNull<T*> WrapNotNullUnchecked(T* const aBasePtr) {
#if defined(__GNUC__)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wnonnull-compare"
#endif
MOZ_ASSERT(aBasePtr);
#if defined(__GNUC__)
# pragma GCC diagnostic pop
#endif
return NotNull<T*>{aBasePtr};
}
namespace detail {
// Extract the pointed-to type from a pointer type (be it raw or smart).