Turn base::optional's DCHECKs into CHECKs.

We really want to catch such errors. (std::optional throws an
exception in some of these cases.)

Change-Id: I7f8c3aff38aed1b3cbe52bcfb92062268fd3b201
Reviewed-on: https://chromium-review.googlesource.com/1177387
Reviewed-by: Jaroslav Sevcik <jarin@chromium.org>
Commit-Queue: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55158}
This commit is contained in:
Georg Neis 2018-08-16 11:54:33 +02:00 committed by Commit Bot
parent 4aa3ad271b
commit 8d7fb5143c

View File

@ -182,16 +182,16 @@ class Optional {
return *this; return *this;
} }
// TODO(mlamouri): can't use 'constexpr' with DCHECK. // TODO(mlamouri): can't use 'constexpr' with CHECK.
const T* operator->() const { const T* operator->() const {
DCHECK(!storage_.is_null_); CHECK(!storage_.is_null_);
return &value(); return &value();
} }
// TODO(mlamouri): using 'constexpr' here breaks compiler that assume it was // TODO(mlamouri): using 'constexpr' here breaks compiler that assume it was
// meant to be 'constexpr const'. // meant to be 'constexpr const'.
T* operator->() { T* operator->() {
DCHECK(!storage_.is_null_); CHECK(!storage_.is_null_);
return &value(); return &value();
} }
@ -214,26 +214,26 @@ class Optional {
// TODO(mlamouri): using 'constexpr' here breaks compiler that assume it was // TODO(mlamouri): using 'constexpr' here breaks compiler that assume it was
// meant to be 'constexpr const'. // meant to be 'constexpr const'.
T& value() & { T& value() & {
DCHECK(!storage_.is_null_); CHECK(!storage_.is_null_);
return storage_.value_; return storage_.value_;
} }
// TODO(mlamouri): can't use 'constexpr' with DCHECK. // TODO(mlamouri): can't use 'constexpr' with CHECK.
const T& value() const & { const T& value() const & {
DCHECK(!storage_.is_null_); CHECK(!storage_.is_null_);
return storage_.value_; return storage_.value_;
} }
// TODO(mlamouri): using 'constexpr' here breaks compiler that assume it was // TODO(mlamouri): using 'constexpr' here breaks compiler that assume it was
// meant to be 'constexpr const'. // meant to be 'constexpr const'.
T&& value() && { T&& value() && {
DCHECK(!storage_.is_null_); CHECK(!storage_.is_null_);
return std::move(storage_.value_); return std::move(storage_.value_);
} }
// TODO(mlamouri): can't use 'constexpr' with DCHECK. // TODO(mlamouri): can't use 'constexpr' with CHECK.
const T&& value() const && { const T&& value() const && {
DCHECK(!storage_.is_null_); CHECK(!storage_.is_null_);
return std::move(storage_.value_); return std::move(storage_.value_);
} }
@ -273,7 +273,7 @@ class Optional {
return; return;
} }
DCHECK(!storage_.is_null_ && !other.storage_.is_null_); CHECK(!storage_.is_null_ && !other.storage_.is_null_);
using std::swap; using std::swap;
swap(**this, *other); swap(**this, *other);
} }
@ -288,20 +288,20 @@ class Optional {
private: private:
void Init(const T& value) { void Init(const T& value) {
DCHECK(storage_.is_null_); CHECK(storage_.is_null_);
new (&storage_.value_) T(value); new (&storage_.value_) T(value);
storage_.is_null_ = false; storage_.is_null_ = false;
} }
void Init(T&& value) { void Init(T&& value) {
DCHECK(storage_.is_null_); CHECK(storage_.is_null_);
new (&storage_.value_) T(std::move(value)); new (&storage_.value_) T(std::move(value));
storage_.is_null_ = false; storage_.is_null_ = false;
} }
template <class... Args> template <class... Args>
void Init(Args&&... args) { void Init(Args&&... args) {
DCHECK(storage_.is_null_); CHECK(storage_.is_null_);
new (&storage_.value_) T(std::forward<Args>(args)...); new (&storage_.value_) T(std::forward<Args>(args)...);
storage_.is_null_ = false; storage_.is_null_ = false;
} }