From d2e73f1115bfed906f2a10dc69aebced6774bac3 Mon Sep 17 00:00:00 2001 From: tzik Date: Wed, 17 Oct 2018 12:38:46 +0000 Subject: [PATCH] Use qualified base::make_optional in optional_unittest.cc Unqualified usage of make_optional causes a compile error if: - It's compiler in C++17 mode and is included. - The parameter of make_optional is in std namespace, such as std::string. As std::make_optional is pulled by ADL rule and conflicts to base::make_optional in this situation. This CL replaces them with qualified base::make_optional, and replaces others for consistency. Change-Id: I2045e9eac0e4466dce266112eab5bf7c8555c2ef Reviewed-on: https://chromium-review.googlesource.com/c/1282512 Reviewed-by: Daniel Cheng Reviewed-by: Hidehiko Abe Commit-Queue: Taiju Tsuiki Cr-Commit-Position: refs/heads/master@{#600361} --- base/optional_unittest.cc | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/base/optional_unittest.cc b/base/optional_unittest.cc index 7bdb46b76173..365e99da41df 100644 --- a/base/optional_unittest.cc +++ b/base/optional_unittest.cc @@ -1899,34 +1899,39 @@ TEST(OptionalTest, NotEqualsNull) { TEST(OptionalTest, MakeOptional) { { - Optional o = make_optional(32.f); + // Use qualified base::make_optional here and elsewhere to avoid the name + // confliction to std::make_optional. + // The name conflict happens only for types in std namespace, such as + // std::string. The other qualified base::make_optional usages are just for + // consistency. + Optional o = base::make_optional(32.f); EXPECT_TRUE(o); EXPECT_EQ(32.f, *o); float value = 3.f; - o = make_optional(std::move(value)); + o = base::make_optional(std::move(value)); EXPECT_TRUE(o); EXPECT_EQ(3.f, *o); } { - Optional o = make_optional(std::string("foo")); + Optional o = base::make_optional(std::string("foo")); EXPECT_TRUE(o); EXPECT_EQ("foo", *o); std::string value = "bar"; - o = make_optional(std::move(value)); + o = base::make_optional(std::move(value)); EXPECT_TRUE(o); EXPECT_EQ(std::string("bar"), *o); } { - Optional o = make_optional(TestObject(3, 0.1)); + Optional o = base::make_optional(TestObject(3, 0.1)); EXPECT_TRUE(!!o); EXPECT_TRUE(TestObject(3, 0.1) == *o); TestObject value = TestObject(0, 0.42); - o = make_optional(std::move(value)); + o = base::make_optional(std::move(value)); EXPECT_TRUE(!!o); EXPECT_TRUE(TestObject(0, 0.42) == *o); EXPECT_EQ(TestObject::State::MOVED_FROM, value.state()); @@ -1945,7 +1950,7 @@ TEST(OptionalTest, MakeOptional) { bool c; }; - Optional o = make_optional(1, 2.0, true); + Optional o = base::make_optional(1, 2.0, true); EXPECT_TRUE(!!o); EXPECT_EQ(1, o->a); EXPECT_EQ(2.0, o->b); @@ -1953,11 +1958,11 @@ TEST(OptionalTest, MakeOptional) { } { - auto str1 = make_optional({'1', '2', '3'}); + auto str1 = base::make_optional({'1', '2', '3'}); EXPECT_EQ("123", *str1); - auto str2 = - make_optional({'a', 'b', 'c'}, std::allocator()); + auto str2 = base::make_optional({'a', 'b', 'c'}, + std::allocator()); EXPECT_EQ("abc", *str2); } } -- 2.20.0.405.gbc1bbc6f85-goog