Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5498)

Unified Diff: base/optional.h

Issue 2453733002: Fix base::Optional constexpr ctor on gcc 4.8. (Closed)
Patch Set: Address review comments Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/optional.h
diff --git a/base/optional.h b/base/optional.h
index a32e06808d82cd7b75b66009880d891e4d62fceb..17b3812b5a0ab4811218ab4aa98479c2dfea8321 100644
--- a/base/optional.h
+++ b/base/optional.h
@@ -34,7 +34,9 @@ namespace internal {
template <typename T, bool = base::is_trivially_destructible<T>::value>
struct OptionalStorage {
- constexpr OptionalStorage() {}
+ // Initializing |empty_| here instead of using default member initializing
+ // to avoid errors in g++ 4.8.
+ constexpr OptionalStorage() : empty_('\0') {}
constexpr explicit OptionalStorage(const T& value)
: is_null_(false), value_(value) {}
@@ -58,16 +60,18 @@ struct OptionalStorage {
bool is_null_ = true;
union {
// |empty_| exists so that the union will always be initialized, even when
- // it doesn't contain a value. Not initializing it has been observed to
- // trigger comiler warnings.
- char empty_ = '\0';
+ // it doesn't contain a value. Union members must be initialized for the
+ // constructor to be 'constexpr'.
+ char empty_;
T value_;
};
};
template <typename T>
struct OptionalStorage<T, true> {
- constexpr OptionalStorage() {}
+ // Initializing |empty_| here instead of using default member initializing
+ // to avoid errors in g++ 4.8.
+ constexpr OptionalStorage() : empty_('\0') {}
constexpr explicit OptionalStorage(const T& value)
: is_null_(false), value_(value) {}
@@ -89,9 +93,9 @@ struct OptionalStorage<T, true> {
bool is_null_ = true;
union {
// |empty_| exists so that the union will always be initialized, even when
- // it doesn't contain a value. Not initializing it has been observed to
- // trigger comiler warnings.
- char empty_ = '\0';
+ // it doesn't contain a value. Union members must be initialized for the
+ // constructor to be 'constexpr'.
+ char empty_;
T value_;
};
};
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698