1From d2e73f1115bfed906f2a10dc69aebced6774bac3 Mon Sep 17 00:00:00 2001
2From: tzik <tzik@chromium.org>
3Date: Wed, 17 Oct 2018 12:38:46 +0000
4Subject: [PATCH] Use qualified base::make_optional in optional_unittest.cc
5
6Unqualified usage of make_optional causes a compile error if:
7 - It's compiler in C++17 mode and <optional> is included.
8 - The parameter of make_optional is in std namespace, such as
9   std::string.
10As std::make_optional is pulled by ADL rule and conflicts to
11base::make_optional in this situation.
12
13This CL replaces them with qualified base::make_optional, and
14replaces others for consistency.
15
16Change-Id: I2045e9eac0e4466dce266112eab5bf7c8555c2ef
17Reviewed-on: https://chromium-review.googlesource.com/c/1282512
18Reviewed-by: Daniel Cheng <dcheng@chromium.org>
19Reviewed-by: Hidehiko Abe <hidehiko@chromium.org>
20Commit-Queue: Taiju Tsuiki <tzik@chromium.org>
21Cr-Commit-Position: refs/heads/master@{#600361}
22---
23 base/optional_unittest.cc | 25 +++++++++++++++----------
24 1 file changed, 15 insertions(+), 10 deletions(-)
25
26diff --git a/base/optional_unittest.cc b/base/optional_unittest.cc
27index 7bdb46b76173..365e99da41df 100644
28--- a/base/optional_unittest.cc
29+++ b/base/optional_unittest.cc
30@@ -1899,34 +1899,39 @@ TEST(OptionalTest, NotEqualsNull) {
31
32 TEST(OptionalTest, MakeOptional) {
33   {
34-    Optional<float> o = make_optional(32.f);
35+    // Use qualified base::make_optional here and elsewhere to avoid the name
36+    // confliction to std::make_optional.
37+    // The name conflict happens only for types in std namespace, such as
38+    // std::string. The other qualified base::make_optional usages are just for
39+    // consistency.
40+    Optional<float> o = base::make_optional(32.f);
41     EXPECT_TRUE(o);
42     EXPECT_EQ(32.f, *o);
43
44     float value = 3.f;
45-    o = make_optional(std::move(value));
46+    o = base::make_optional(std::move(value));
47     EXPECT_TRUE(o);
48     EXPECT_EQ(3.f, *o);
49   }
50
51   {
52-    Optional<std::string> o = make_optional(std::string("foo"));
53+    Optional<std::string> o = base::make_optional(std::string("foo"));
54     EXPECT_TRUE(o);
55     EXPECT_EQ("foo", *o);
56
57     std::string value = "bar";
58-    o = make_optional(std::move(value));
59+    o = base::make_optional(std::move(value));
60     EXPECT_TRUE(o);
61     EXPECT_EQ(std::string("bar"), *o);
62   }
63
64   {
65-    Optional<TestObject> o = make_optional(TestObject(3, 0.1));
66+    Optional<TestObject> o = base::make_optional(TestObject(3, 0.1));
67     EXPECT_TRUE(!!o);
68     EXPECT_TRUE(TestObject(3, 0.1) == *o);
69
70     TestObject value = TestObject(0, 0.42);
71-    o = make_optional(std::move(value));
72+    o = base::make_optional(std::move(value));
73     EXPECT_TRUE(!!o);
74     EXPECT_TRUE(TestObject(0, 0.42) == *o);
75     EXPECT_EQ(TestObject::State::MOVED_FROM, value.state());
76@@ -1945,7 +1950,7 @@ TEST(OptionalTest, MakeOptional) {
77       bool c;
78     };
79
80-    Optional<Test> o = make_optional<Test>(1, 2.0, true);
81+    Optional<Test> o = base::make_optional<Test>(1, 2.0, true);
82     EXPECT_TRUE(!!o);
83     EXPECT_EQ(1, o->a);
84     EXPECT_EQ(2.0, o->b);
85@@ -1953,11 +1958,11 @@ TEST(OptionalTest, MakeOptional) {
86   }
87
88   {
89-    auto str1 = make_optional<std::string>({'1', '2', '3'});
90+    auto str1 = base::make_optional<std::string>({'1', '2', '3'});
91     EXPECT_EQ("123", *str1);
92
93-    auto str2 =
94-        make_optional<std::string>({'a', 'b', 'c'}, std::allocator<char>());
95+    auto str2 = base::make_optional<std::string>({'a', 'b', 'c'},
96+                                                 std::allocator<char>());
97     EXPECT_EQ("abc", *str2);
98   }
99 }
100--
1012.20.0.405.gbc1bbc6f85-goog
102
103