Skip to content

Commit

Permalink
Bug 1374629 - Ensure that mozilla::NotNull has zero space overhead. r…
Browse files Browse the repository at this point in the history
…=njn

MozReview-Commit-ID: 9Bo2qxd3HRv

--HG--
extra : rebase_source : 5e19d7c405f243b602ee2beca3a94b880eddb27e
  • Loading branch information
vyv03354 committed Jun 21, 2017
1 parent 7faf369 commit 14bf5a0
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion mfbt/NotNull.h
Original file line number Diff line number Diff line change
@@ -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 @@ class NotNull

// 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;

0 comments on commit 14bf5a0

Please sign in to comment.