diff -up chromium-65.0.3325.146/base/optional.h.affirmative chromium-65.0.3325.146/base/optional.h --- chromium-65.0.3325.146/base/optional.h.affirmative 2018-03-13 22:27:29.451969704 -0400 +++ chromium-65.0.3325.146/base/optional.h 2018-03-13 22:27:57.031436045 -0400 @@ -41,7 +41,7 @@ struct OptionalStorageBase { template constexpr explicit OptionalStorageBase(in_place_t, Args&&... args) - : is_null_(false), value_(std::forward(args)...) {} + : is_populated_(true), value_(std::forward(args)...) {} // When T is not trivially destructible we must call its // destructor before deallocating its memory. @@ -55,18 +55,18 @@ struct OptionalStorageBase { // necessary for this case at the moment. Please see also the destructor // comment in "is_trivially_destructible = true" specialization below. ~OptionalStorageBase() { - if (!is_null_) + if (is_populated_) value_.~T(); } template void Init(Args&&... args) { - DCHECK(is_null_); + DCHECK(!is_populated_); ::new (&value_) T(std::forward(args)...); - is_null_ = false; + is_populated_ = true; } - bool is_null_ = true; + bool is_populated_ = false; union { // |empty_| exists so that the union will always be initialized, even when // it doesn't contain a value. Union members must be initialized for the @@ -84,7 +84,7 @@ struct OptionalStorageBase constexpr explicit OptionalStorageBase(in_place_t, Args&&... args) - : is_null_(false), value_(std::forward(args)...) {} + : is_populated_(true), value_(std::forward(args)...) {} // When T is trivially destructible (i.e. its destructor does nothing) there // is no need to call it. Implicitly defined destructor is trivial, because @@ -102,12 +102,12 @@ struct OptionalStorageBase void Init(Args&&... args) { - DCHECK(is_null_); + DCHECK(!is_populated_); ::new (&value_) T(std::forward(args)...); - is_null_ = false; + is_populated_ = true; } - bool is_null_ = true; + bool is_populated_ = false; union { // |empty_| exists so that the union will always be initialized, even when // it doesn't contain a value. Union members must be initialized for the @@ -133,7 +133,7 @@ struct OptionalStorage : OptionalStorage // Accessing the members of template base class requires explicit // declaration. - using OptionalStorageBase::is_null_; + using OptionalStorageBase::is_populated_; using OptionalStorageBase::value_; using OptionalStorageBase::Init; @@ -145,12 +145,12 @@ struct OptionalStorage : OptionalStorage OptionalStorage() = default; OptionalStorage(const OptionalStorage& other) { - if (!other.is_null_) + if (other.is_populated_) Init(other.value_); } OptionalStorage(OptionalStorage&& other) { - if (!other.is_null_) + if (other.is_populated_) Init(std::move(other.value_)); } }; @@ -160,7 +160,7 @@ struct OptionalStorage : OptionalStorageBase { - using OptionalStorageBase::is_null_; + using OptionalStorageBase::is_populated_; using OptionalStorageBase::value_; using OptionalStorageBase::Init; using OptionalStorageBase::OptionalStorageBase; @@ -169,7 +169,7 @@ struct OptionalStorage : OptionalStorageBase { - using OptionalStorageBase::is_null_; + using OptionalStorageBase::is_populated_; using OptionalStorageBase::value_; using OptionalStorageBase::Init; using OptionalStorageBase::OptionalStorageBase; @@ -188,7 +188,7 @@ struct OptionalStorage storage_; @@ -334,12 +334,12 @@ class Optional : public internal::Option } constexpr const T* operator->() const { - DCHECK(!storage_.is_null_); + DCHECK(storage_.is_populated_); return &value(); } constexpr T* operator->() { - DCHECK(!storage_.is_null_); + DCHECK(storage_.is_populated_); return &value(); } @@ -351,27 +351,27 @@ class Optional : public internal::Option constexpr T&& operator*() && { return std::move(value()); } - constexpr explicit operator bool() const { return !storage_.is_null_; } + constexpr explicit operator bool() const { return storage_.is_populated_; } - constexpr bool has_value() const { return !storage_.is_null_; } + constexpr bool has_value() const { return storage_.is_populated_; } constexpr T& value() & { - DCHECK(!storage_.is_null_); + DCHECK(storage_.is_populated_); return storage_.value_; } constexpr const T& value() const & { - DCHECK(!storage_.is_null_); + DCHECK(storage_.is_populated_); return storage_.value_; } constexpr T&& value() && { - DCHECK(!storage_.is_null_); + DCHECK(storage_.is_populated_); return std::move(storage_.value_); } constexpr const T&& value() const && { - DCHECK(!storage_.is_null_); + DCHECK(storage_.is_populated_); return std::move(storage_.value_); } @@ -382,8 +382,9 @@ class Optional : public internal::Option // "T must be copy constructible"); static_assert(std::is_convertible::value, "U must be convertible to T"); - return storage_.is_null_ ? static_cast(std::forward(default_value)) - : value(); + return storage_.is_populated_ + ? value() + : static_cast(std::forward(default_value)); } template @@ -393,26 +394,27 @@ class Optional : public internal::Option // "T must be move constructible"); static_assert(std::is_convertible::value, "U must be convertible to T"); - return storage_.is_null_ ? static_cast(std::forward(default_value)) - : std::move(value()); + return storage_.is_populated_ + ? std::move(value()) + : static_cast(std::forward(default_value)); } void swap(Optional& other) { - if (storage_.is_null_ && other.storage_.is_null_) + if (!storage_.is_populated_ && !other.storage_.is_populated_) return; - if (storage_.is_null_ != other.storage_.is_null_) { - if (storage_.is_null_) { - storage_.Init(std::move(other.storage_.value_)); - other.FreeIfNeeded(); - } else { + if (storage_.is_populated_ != other.storage_.is_populated_) { + if (storage_.is_populated_) { other.storage_.Init(std::move(storage_.value_)); FreeIfNeeded(); + } else { + storage_.Init(std::move(other.storage_.value_)); + other.FreeIfNeeded(); } return; } - DCHECK(!storage_.is_null_ && !other.storage_.is_null_); + DCHECK(storage_.is_populated_ && other.storage_.is_populated_); using std::swap; swap(**this, *other); }