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

Unified Diff: base/optional_unittest.cc

Issue 2437313002: base::Optional operator bool doesn't convert to bool. (Closed)
Patch Set: 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_unittest.cc
diff --git a/base/optional_unittest.cc b/base/optional_unittest.cc
index 565b6cd6c74cad6679c02c68953176b0dce11c6f..f79490bd8cb5c8da6fe76a6f422712a524c91a89 100644
--- a/base/optional_unittest.cc
+++ b/base/optional_unittest.cc
@@ -441,6 +441,29 @@ TEST(OptionalTest, OperatorArrow) {
EXPECT_EQ(a->foo(), 3);
}
+TEST(OptionalTest, OperatorBool) {
+ {
+ Optional<TestObject> a;
+ EXPECT_EQ(static_cast<bool>(a), false); // works.
+ }
+
+ {
+ Optional<TestObject> a;
+ bool b = !!a; // works.
+ EXPECT_EQ(b, false);
+ }
+
+ {
+ Optional<TestObject> a;
+ bool b = a;
+ // error: no viable conversion from
+ // 'Optional<base::(anonymous namespace)::TestObject>' to 'bool'
+ EXPECT_EQ(b, false);
+ }
+
+ // More to add here... testing true etc.
+}
+
TEST(OptionalTest, Value_rvalue) {
EXPECT_EQ(0.1f, Optional<float>(0.1f).value());
EXPECT_EQ(std::string("foo"), Optional<std::string>("foo").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