Bug 1463011 - Constexpr-ify mozilla::NotNull r?njn draft
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Wed, 15 Nov 2017 22:52:04 +0900
changeset 797687 99c483505cef309659ec74add4dacf232bf1b151
parent 797542 ffec9a9853918d6a254ef08e8e3982e90ab63801
push id110537
push userVYV03354@nifty.ne.jp
push dateMon, 21 May 2018 11:43:43 +0000
reviewersnjn
bugs1463011
milestone62.0a1
Bug 1463011 - Constexpr-ify mozilla::NotNull r?njn MozReview-Commit-ID: EyXmRskjtfU
build/moz.configure/windows.configure
mfbt/NotNull.h
--- a/build/moz.configure/windows.configure
+++ b/build/moz.configure/windows.configure
@@ -233,18 +233,18 @@ def valid_ucrt_sdk_dir(windows_sdk_dir, 
         raise FatalCheckError('Latest Universal CRT SDK version found %s'
                               ' and minimum required is %s. This or a later'
                               ' version can be installed using the Visual'
                               ' Studio installer.'
                               % (version, minimum_ucrt_version))
 
     broken_ucrt_version = Version('10.0.16299.0')
     working_ucrt_version = Version('10.0.17134.0')
-    if (c_compiler.type == 'clang-cl' and version >= broken_ucrt_version
-        and version < working_ucrt_version):
+    if (c_compiler.type == 'clang-cl' and version >= broken_ucrt_version and
+            version < working_ucrt_version):
         raise FatalCheckError('Found SDK version %s but clang-cl builds'
                               ' currently don\'t work with the SDK version.'
                               ' You should use a different version, either'
                               ' by uninstalling version %s or setting a'
                               ' custom WINDOWSSDKDIR.\n'
                               'Note: Version %s now works with clang-cl.'
                               % (version, version, working_ucrt_version))
 
--- a/mfbt/NotNull.h
+++ b/mfbt/NotNull.h
@@ -97,33 +97,35 @@ namespace mozilla {
 //   checks.
 //
 // NotNull currently doesn't work with UniquePtr. See
 // https://github.com/Microsoft/GSL/issues/89 for some discussion.
 //
 template <typename T>
 class NotNull
 {
-  template <typename U> friend NotNull<U> WrapNotNull(U aBasePtr);
+  template <typename U> friend constexpr NotNull<U> WrapNotNull(U aBasePtr);
   template<typename U, typename... Args>
-  friend NotNull<U> MakeNotNull(Args&&... aArgs);
+  friend constexpr NotNull<U> MakeNotNull(Args&&... aArgs);
 
   T mBasePtr;
 
   // This constructor is only used by WrapNotNull() and MakeNotNull<U>().
   template <typename U>
-  explicit NotNull(U aBasePtr) : mBasePtr(aBasePtr) {}
+  constexpr explicit NotNull(U aBasePtr) : mBasePtr(aBasePtr) {}
 
 public:
   // Disallow default construction.
   NotNull() = delete;
 
   // Construct/assign from another NotNull with a compatible base pointer type.
   template <typename U>
-  MOZ_IMPLICIT NotNull(const NotNull<U>& aOther) : mBasePtr(aOther.get()) {
+  constexpr 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;
@@ -131,28 +133,28 @@ public:
   NotNull(NotNull<T>&&) = default;
   NotNull<T>& operator=(NotNull<T>&&) = default;
 
   // Disallow null checks, which are unnecessary for this type.
   explicit operator bool() const = delete;
 
   // Explicit conversion to a base pointer. Use only to resolve ambiguity or to
   // get a castable pointer.
-  const T& get() const { return mBasePtr; }
+  constexpr const T& get() const { return mBasePtr; }
 
   // Implicit conversion to a base pointer. Preferable to get().
-  operator const T&() const { return get(); }
+  constexpr operator const T&() const { return get(); }
 
   // Dereference operators.
-  const T& operator->() const { return get(); }
-  decltype(*mBasePtr) operator*() const { return *mBasePtr; }
+  constexpr const T& operator->() const { return get(); }
+  constexpr decltype(*mBasePtr) operator*() const { return *mBasePtr; }
 };
 
 template <typename T>
-NotNull<T>
+constexpr NotNull<T>
 WrapNotNull(const T aBasePtr)
 {
   NotNull<T> notNull(aBasePtr);
   MOZ_RELEASE_ASSERT(aBasePtr);
   return notNull;
 }
 
 namespace detail {
@@ -187,62 +189,62 @@ struct PointedTo<const T*>
 };
 
 } // namespace detail
 
 // Allocate an object with infallible new, and wrap its pointer in NotNull.
 // |MakeNotNull<Ptr<Ob>>(args...)| will run |new Ob(args...)|
 // and return NotNull<Ptr<Ob>>.
 template<typename T, typename... Args>
-NotNull<T>
+constexpr NotNull<T>
 MakeNotNull(Args&&... aArgs)
 {
   using Pointee = typename detail::PointedTo<T>::NonConstType;
   static_assert(!IsArray<Pointee>::value,
                 "MakeNotNull cannot construct an array");
   return NotNull<T>(new Pointee(Forward<Args>(aArgs)...));
 }
 
 // Compare two NotNulls.
 template <typename T, typename U>
-inline bool
+constexpr bool
 operator==(const NotNull<T>& aLhs, const NotNull<U>& aRhs)
 {
   return aLhs.get() == aRhs.get();
 }
 template <typename T, typename U>
-inline bool
+constexpr bool
 operator!=(const NotNull<T>& aLhs, const NotNull<U>& aRhs)
 {
   return aLhs.get() != aRhs.get();
 }
 
 // Compare a NotNull to a base pointer.
 template <typename T, typename U>
-inline bool
+constexpr bool
 operator==(const NotNull<T>& aLhs, const U& aRhs)
 {
   return aLhs.get() == aRhs;
 }
 template <typename T, typename U>
-inline bool
+constexpr bool
 operator!=(const NotNull<T>& aLhs, const U& aRhs)
 {
   return aLhs.get() != aRhs;
 }
 
 // Compare a base pointer to a NotNull.
 template <typename T, typename U>
-inline bool
+constexpr bool
 operator==(const T& aLhs, const NotNull<U>& aRhs)
 {
   return aLhs == aRhs.get();
 }
 template <typename T, typename U>
-inline bool
+constexpr bool
 operator!=(const T& aLhs, const NotNull<U>& aRhs)
 {
   return aLhs != aRhs.get();
 }
 
 // Disallow comparing a NotNull to a nullptr.
 template <typename T>
 bool