diff --git a/llvm/include/llvm/ADT/Optional.h b/llvm/include/llvm/ADT/Optional.h --- a/llvm/include/llvm/ADT/Optional.h +++ b/llvm/include/llvm/ADT/Optional.h @@ -318,7 +318,9 @@ template constexpr T value_or(U &&alt) const & { return has_value() ? value() : std::forward(alt); } - template constexpr T getValueOr(U &&alt) const & { + template + [[deprecated("Use value_or instead.")]] constexpr T + getValueOr(U &&alt) const & { return has_value() ? value() : std::forward(alt); } @@ -337,7 +339,8 @@ template T value_or(U &&alt) && { return has_value() ? std::move(value()) : std::forward(alt); } - template T getValueOr(U &&alt) && { + template + [[deprecated("Use value_or instead.")]] T getValueOr(U &&alt) && { return has_value() ? std::move(value()) : std::forward(alt); } diff --git a/llvm/unittests/ADT/OptionalTest.cpp b/llvm/unittests/ADT/OptionalTest.cpp --- a/llvm/unittests/ADT/OptionalTest.cpp +++ b/llvm/unittests/ADT/OptionalTest.cpp @@ -210,11 +210,9 @@ TEST(OptionalTest, GetValueOr) { Optional A; EXPECT_EQ(42, A.value_or(42)); - EXPECT_EQ(42, A.getValueOr(42)); A = 5; EXPECT_EQ(5, A.value_or(42)); - EXPECT_EQ(5, A.getValueOr(42)); } struct MultiArgConstructor { @@ -605,23 +603,6 @@ EXPECT_EQ(2u, MoveOnly::Destructions); } -TEST(OptionalTest, MoveGetValueOr) { - Optional A; - - MoveOnly::ResetCounts(); - EXPECT_EQ(42, std::move(A).getValueOr(MoveOnly(42)).val); - EXPECT_EQ(1u, MoveOnly::MoveConstructions); - EXPECT_EQ(0u, MoveOnly::MoveAssignments); - EXPECT_EQ(2u, MoveOnly::Destructions); - - A = MoveOnly(5); - MoveOnly::ResetCounts(); - EXPECT_EQ(5, std::move(A).getValueOr(MoveOnly(42)).val); - EXPECT_EQ(1u, MoveOnly::MoveConstructions); - EXPECT_EQ(0u, MoveOnly::MoveAssignments); - EXPECT_EQ(2u, MoveOnly::Destructions); -} - struct EqualTo { template static bool apply(const T &X, const U &Y) { return X == Y;