Skip to content

Commit

Permalink
Backed out changeset 5200dd8a0de5 (bug 1645328) for cppunit assertion…
Browse files Browse the repository at this point in the history
… failures at Maybe.h. CLOSED TREE
  • Loading branch information
cristianbrindusan committed Jun 12, 2020
1 parent d4ba9b8 commit df6529b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 33 deletions.
20 changes: 3 additions & 17 deletions mfbt/Maybe.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,6 @@ struct MaybeStorage<T, false> {
explicit MaybeStorage(const T& aVal) : mStorage{aVal}, mIsSome{true} {}
explicit MaybeStorage(T&& aVal) : mStorage{std::move(aVal)}, mIsSome{true} {}

template <typename... Args>
explicit MaybeStorage(Args&&... aArgs) : mIsSome{true} {
::new (KnownNotNull, &mStorage.val) T(std::forward<Args>(aArgs)...);
}

// Copy and move operations are no-ops, since copying is moving is implemented
// by Maybe_CopyMove_Enabler.

Expand Down Expand Up @@ -304,14 +299,6 @@ struct MaybeStorage<T, true> {
: mStorage{aVal}, mIsSome{true} {}
constexpr explicit MaybeStorage(T&& aVal)
: mStorage{std::move(aVal)}, mIsSome{true} {}

// XXX This should be constexpr, but then we can't use placement new.
// Delegating this to a Union constructor with the same signature doesn't
// build out of the box.
template <typename... Args>
explicit MaybeStorage(Args&&... aArgs) : mIsSome{true} {
::new (KnownNotNull, &mStorage.val) T(std::forward<Args>(aArgs)...);
}
};

} // namespace detail
Expand Down Expand Up @@ -363,6 +350,9 @@ constexpr Maybe<U> Some(T&& aValue);
* Boost. The most important differences between Maybe and std::optional are:
*
* - std::optional<T> may be compared with T. We deliberately forbid that.
* - std::optional allows in-place construction without a separate call to
* |emplace()| by using a dummy |in_place_t| value to tag the appropriate
* constructor.
* - std::optional has |valueOr()|, equivalent to Maybe's |valueOr()|, but
* lacks corresponding methods for |refOr()| and |ptrOr()|.
* - std::optional lacks |map()| and |apply()|, making it less suitable for
Expand Down Expand Up @@ -399,10 +389,6 @@ class MOZ_INHERIT_TYPE_ANNOTATIONS_FROM_TEMPLATE_ARGS Maybe

MOZ_ALLOW_TEMPORARY MOZ_IMPLICIT constexpr Maybe(Nothing) : Maybe{} {}

template <typename... Args>
constexpr explicit Maybe(std::in_place_t, Args&&... aArgs)
: detail::MaybeStorage<T>(std::forward<Args>(aArgs)...) {}

/**
* Maybe<T> can be copy-constructed from a Maybe<U> if T is constructible from
* a const U&.
Expand Down
17 changes: 1 addition & 16 deletions mfbt/tests/TestMaybe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ struct UncopyableUnmovableValue {

~UncopyableUnmovableValue() { --sUndestroyedObjects; }

Status GetStatus() const { return mStatus; }
Status GetStatus() { return mStatus; }

private:
UncopyableUnmovableValue(const UncopyableUnmovableValue& aOther) = delete;
Expand Down Expand Up @@ -261,14 +261,6 @@ static bool TestBasicFeatures() {
mayValue.reset();
MOZ_RELEASE_ASSERT(!mayValue);

{
// Check that Maybe(std::in_place, T1) calls the correct constructor.
const auto mayValueConstructed = Maybe<BasicValue>(std::in_place, 1);
MOZ_RELEASE_ASSERT(mayValueConstructed);
MOZ_RELEASE_ASSERT(mayValueConstructed->GetStatus() == eWasConstructed);
MOZ_RELEASE_ASSERT(mayValueConstructed->GetTag() == 1);
}

// Check that Some() and Nothing() work.
mayValue = Some(BasicValue(2));
MOZ_RELEASE_ASSERT(mayValue);
Expand Down Expand Up @@ -505,13 +497,6 @@ static bool TestCopyAndMove() {
MOZ_RELEASE_ASSERT(0 == sUndestroyedObjects);

{ // Check that types that support neither moves or copies work.
{
const auto mayUncopyableUnmovableValueConstructed =
Maybe<UncopyableUnmovableValue>{std::in_place};
MOZ_RELEASE_ASSERT(mayUncopyableUnmovableValueConstructed->GetStatus() ==
eWasDefaultConstructed);
}

Maybe<UncopyableUnmovableValue> mayUncopyableUnmovableValue;
mayUncopyableUnmovableValue.emplace();
MOZ_RELEASE_ASSERT(mayUncopyableUnmovableValue->GetStatus() ==
Expand Down

0 comments on commit df6529b

Please sign in to comment.