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

Unified Diff: webrtc/base/optional.h

Issue 2090223003: Added an empty member to the union of rtc::Optional, so that it is always initializable. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Removed else clauses; added explanatory comment. Created 4 years, 6 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: webrtc/base/optional.h
diff --git a/webrtc/base/optional.h b/webrtc/base/optional.h
index 25cfbfe41752597d340864f3cc46ce56794763b4..e98ab2e3ce7e9765386bcb8cbb47c92f4a7b42fa 100644
--- a/webrtc/base/optional.h
+++ b/webrtc/base/optional.h
@@ -59,7 +59,7 @@ template <typename T>
class Optional final {
public:
// Construct an empty Optional.
- Optional() : has_value_(false) {}
+ Optional() : has_value_(false), empty_('\0') {}
// Construct an Optional that contains a value.
explicit Optional(const T& value) : has_value_(true) {
@@ -189,6 +189,10 @@ class Optional final {
private:
bool has_value_; // True iff value_ contains a live value.
union {
+ // empty_ exists only to make it possible to initialize the union, even when
+ // it doesn't contain any data. If the union goes uninitialized, it may
+ // trigger compiler warnings.
+ char empty_;
// By placing value_ in a union, we get to manage its construction and
// destruction manually: the Optional constructors won't automatically
// construct it, and the Optional destructor won't automatically destroy
« 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