Commit 8d7fb514 authored by Georg Neis's avatar Georg Neis Committed by Commit Bot

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/1177387Reviewed-by: 's avatarJaroslav Sevcik <jarin@chromium.org>
Commit-Queue: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55158}
parent 4aa3ad27
......@@ -182,16 +182,16 @@ class Optional {
return *this;
}
// TODO(mlamouri): can't use 'constexpr' with DCHECK.
// TODO(mlamouri): can't use 'constexpr' with CHECK.
const T* operator->() const {
DCHECK(!storage_.is_null_);
CHECK(!storage_.is_null_);
return &value();
}
// TODO(mlamouri): using 'constexpr' here breaks compiler that assume it was
// meant to be 'constexpr const'.
T* operator->() {
DCHECK(!storage_.is_null_);
CHECK(!storage_.is_null_);
return &value();
}
......@@ -214,26 +214,26 @@ class Optional {
// TODO(mlamouri): using 'constexpr' here breaks compiler that assume it was
// meant to be 'constexpr const'.
T& value() & {
DCHECK(!storage_.is_null_);
CHECK(!storage_.is_null_);
return storage_.value_;
}
// TODO(mlamouri): can't use 'constexpr' with DCHECK.
// TODO(mlamouri): can't use 'constexpr' with CHECK.
const T& value() const & {
DCHECK(!storage_.is_null_);
CHECK(!storage_.is_null_);
return storage_.value_;
}
// TODO(mlamouri): using 'constexpr' here breaks compiler that assume it was
// meant to be 'constexpr const'.
T&& value() && {
DCHECK(!storage_.is_null_);
CHECK(!storage_.is_null_);
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 && {
DCHECK(!storage_.is_null_);
CHECK(!storage_.is_null_);
return std::move(storage_.value_);
}
......@@ -273,7 +273,7 @@ class Optional {
return;
}
DCHECK(!storage_.is_null_ && !other.storage_.is_null_);
CHECK(!storage_.is_null_ && !other.storage_.is_null_);
using std::swap;
swap(**this, *other);
}
......@@ -288,20 +288,20 @@ class Optional {
private:
void Init(const T& value) {
DCHECK(storage_.is_null_);
CHECK(storage_.is_null_);
new (&storage_.value_) T(value);
storage_.is_null_ = false;
}
void Init(T&& value) {
DCHECK(storage_.is_null_);
CHECK(storage_.is_null_);
new (&storage_.value_) T(std::move(value));
storage_.is_null_ = false;
}
template <class... Args>
void Init(Args&&... args) {
DCHECK(storage_.is_null_);
CHECK(storage_.is_null_);
new (&storage_.value_) T(std::forward<Args>(args)...);
storage_.is_null_ = false;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment