Bug 1612135 - Allow Result<V, E> to be used with a MOZ_NON_PARAM_TYPE E. r=emilio,froydnj
authorSimon Giesecke <sgiesecke@mozilla.com>
Wed, 29 Jan 2020 21:22:39 +0000
changeset 512089 cb607bf4c55f687bfbf3e298dc4073ddcd10a945
parent 512088 7b794b53736c781545273accf33ed5bd23d0abea
child 512090 94d79e1b849ef7b7c33be1f9bd57e904d9433d6a
push id37072
push usercsabou@mozilla.com
push dateThu, 30 Jan 2020 15:44:43 +0000
treeherdermozilla-central@f97c48da9cee [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio, froydnj
bugs1612135
milestone74.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1612135 - Allow Result<V, E> to be used with a MOZ_NON_PARAM_TYPE E. r=emilio,froydnj Differential Revision: https://phabricator.services.mozilla.com/D61214
mfbt/Result.h
--- a/mfbt/Result.h
+++ b/mfbt/Result.h
@@ -51,17 +51,18 @@ class ResultImplementation<V, E, Packing
   ResultImplementation(ResultImplementation&&) = default;
   ResultImplementation(const ResultImplementation&) = default;
   ResultImplementation& operator=(const ResultImplementation&) = default;
   ResultImplementation& operator=(ResultImplementation&&) = default;
 
   explicit ResultImplementation(V&& aValue)
       : mStorage(std::forward<V>(aValue)) {}
   explicit ResultImplementation(const V& aValue) : mStorage(aValue) {}
-  explicit ResultImplementation(E aErrorValue)
+  explicit ResultImplementation(const E& aErrorValue) : mStorage(aErrorValue) {}
+  explicit ResultImplementation(E&& aErrorValue)
       : mStorage(std::forward<E>(aErrorValue)) {}
 
   bool isOk() const { return mStorage.template is<V>(); }
 
   // The callers of these functions will assert isOk() has the proper value, so
   // these functions (in all ResultImplementation specializations) don't need
   // to do so.
   V unwrap() { return std::move(mStorage.template as<V>()); }
@@ -512,17 +513,17 @@ class MOZ_MUST_USE_TYPE Result final {
 template <typename E>
 class MOZ_MUST_USE_TYPE GenericErrorResult {
   E mErrorValue;
 
   template <typename V, typename E2>
   friend class Result;
 
  public:
-  explicit GenericErrorResult(E aErrorValue)
+  explicit GenericErrorResult(E&& aErrorValue)
       : mErrorValue(std::forward<E>(aErrorValue)) {}
 };
 
 template <typename E>
 inline GenericErrorResult<E> Err(E&& aErrorValue) {
   return GenericErrorResult<E>(std::forward<E>(aErrorValue));
 }