From 1792821c8308755593c114c3b7ae8ce33bdb08e9 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sat, 17 Dec 2022 22:43:03 +0000 Subject: [PATCH] Optional: Deprecated value() 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 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/llvm/include/llvm/ADT/Optional.h b/llvm/include/llvm/ADT/Optional.h index 331c681..a458ccf 100644 --- a/llvm/include/llvm/ADT/Optional.h +++ b/llvm/include/llvm/ADT/Optional.h @@ -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(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()); } -- 2.7.4