[llvm] c8cf669 - [ADT] Deprecate Optional::getValueOr (NFC)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 25 23:01:23 PDT 2022


Author: Kazu Hirata
Date: 2022-07-25T23:01:02-07:00
New Revision: c8cf669f6025bdf0fc227f3ddbbf3523a5b32f0b

URL: https://github.com/llvm/llvm-project/commit/c8cf669f6025bdf0fc227f3ddbbf3523a5b32f0b
DIFF: https://github.com/llvm/llvm-project/commit/c8cf669f6025bdf0fc227f3ddbbf3523a5b32f0b.diff

LOG: [ADT] Deprecate Optional::getValueOr (NFC)

This patch deprecates getValueOr in favor of value_or.

Differential Revision: https://reviews.llvm.org/D130140

Added: 
    

Modified: 
    llvm/include/llvm/ADT/Optional.h
    llvm/unittests/ADT/OptionalTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/Optional.h b/llvm/include/llvm/ADT/Optional.h
index d1615d903e98d..e164dc01c8401 100644
--- a/llvm/include/llvm/ADT/Optional.h
+++ b/llvm/include/llvm/ADT/Optional.h
@@ -318,7 +318,9 @@ template <typename T> class Optional {
   template <typename U> constexpr T value_or(U &&alt) const & {
     return has_value() ? value() : std::forward<U>(alt);
   }
-  template <typename U> constexpr T getValueOr(U &&alt) const & {
+  template <typename U>
+  [[deprecated("Use value_or instead.")]] constexpr T
+  getValueOr(U &&alt) const & {
     return has_value() ? value() : std::forward<U>(alt);
   }
 
@@ -337,7 +339,8 @@ template <typename T> class Optional {
   template <typename U> T value_or(U &&alt) && {
     return has_value() ? std::move(value()) : std::forward<U>(alt);
   }
-  template <typename U> T getValueOr(U &&alt) && {
+  template <typename U>
+  [[deprecated("Use value_or instead.")]] T getValueOr(U &&alt) && {
     return has_value() ? std::move(value()) : std::forward<U>(alt);
   }
 

diff  --git a/llvm/unittests/ADT/OptionalTest.cpp b/llvm/unittests/ADT/OptionalTest.cpp
index dac88236a09b3..8d01b0df3fc34 100644
--- a/llvm/unittests/ADT/OptionalTest.cpp
+++ b/llvm/unittests/ADT/OptionalTest.cpp
@@ -210,11 +210,9 @@ TEST(OptionalTest, InPlaceConstructionNonDefaultConstructibleTest) {
 TEST(OptionalTest, GetValueOr) {
   Optional<int> 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 @@ TEST(OptionalTest, MoveValueOr) {
   EXPECT_EQ(2u, MoveOnly::Destructions);
 }
 
-TEST(OptionalTest, MoveGetValueOr) {
-  Optional<MoveOnly> 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 <typename T, typename U> static bool apply(const T &X, const U &Y) {
     return X == Y;


        


More information about the llvm-commits mailing list