Bug 1374629 - Ensure that mozilla::NotNull has zero space overhead. r=njn

MozReview-Commit-ID: 9Bo2qxd3HRv

--HG--
extra : rebase_source : e35aec9978f13092d91141955effb0942e84e70c
This commit is contained in:
Masatoshi Kimura 2017-06-22 00:52:28 +09:00
Родитель bdc7c83579
Коммит 5480e54c73
1 изменённых файлов: 7 добавлений и 1 удалений

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

@ -63,6 +63,7 @@
// for the last one, where the handle type is |void|. See below.
#include "mozilla/Assertions.h"
#include <stddef.h>
namespace mozilla {
@ -114,7 +115,12 @@ public:
// Construct/assign from another NotNull with a compatible base pointer type.
template <typename U>
MOZ_IMPLICIT NotNull(const NotNull<U>& aOther) : mBasePtr(aOther.get()) {}
MOZ_IMPLICIT NotNull(const NotNull<U>& aOther) : mBasePtr(aOther.get()) {
static_assert(sizeof(T) == sizeof(NotNull<T>),
"NotNull must have zero space overhead.");
static_assert(offsetof(NotNull<T>, mBasePtr) == 0,
"mBasePtr must have zero offset.");
}
// Default copy/move construction and assignment.
NotNull(const NotNull<T>&) = default;