Optional: Deprecated value()
authorFangrui Song <i@maskray.me>
Sat, 17 Dec 2022 22:43:03 +0000 (22:43 +0000)
committerFangrui Song <i@maskray.me>
Sat, 17 Dec 2022 22:43:03 +0000 (22:43 +0000)
https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716/19

value() is a 15.0.0 API for std::optional migration.
std::optional::value() has undesired exception checking semantics and is
unavailable in older Xcode (see
_LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS). Deprecate value() to prevent
new in-tree uses which may accidentally cause build breakage for older
Xcode when contributors perform std::optional migrating.

Some downtream MLIR projects such as tensorflow/mlir-hlo, stablehlo use
value(), so we do not remove it now.

llvm/include/llvm/ADT/Optional.h

index 331c681..a458ccf 100644 (file)
@@ -270,7 +270,9 @@ public:
   constexpr const T *getPointer() const { return &Storage.value(); }
   LLVM_DEPRECATED("Use &*X instead.", "&*X")
   T *getPointer() { return &Storage.value(); }
+  LLVM_DEPRECATED("std::optional::value is throwing. Use *X instead", "*X")
   constexpr const T &value() const & { return Storage.value(); }
+  LLVM_DEPRECATED("std::optional::value is throwing. Use *X instead", "*X")
   T &value() & { return Storage.value(); }
 
   constexpr explicit operator bool() const { return has_value(); }
@@ -284,6 +286,7 @@ public:
     return has_value() ? operator*() : std::forward<U>(alt);
   }
 
+  LLVM_DEPRECATED("std::optional::value is throwing. Use *X instead", "*X")
   T &&value() && { return std::move(Storage.value()); }
   T &&operator*() && { return std::move(Storage.value()); }