[llvm] 1792821 - Optional: Deprecated value()
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Dec 17 14:43:09 PST 2022
Author: Fangrui Song
Date: 2022-12-17T22:43:03Z
New Revision: 1792821c8308755593c114c3b7ae8ce33bdb08e9
URL: https://github.com/llvm/llvm-project/commit/1792821c8308755593c114c3b7ae8ce33bdb08e9
DIFF: https://github.com/llvm/llvm-project/commit/1792821c8308755593c114c3b7ae8ce33bdb08e9.diff
LOG: 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.
Added:
Modified:
llvm/include/llvm/ADT/Optional.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/ADT/Optional.h b/llvm/include/llvm/ADT/Optional.h
index 331c681342ad..a458ccf61c71 100644
--- a/llvm/include/llvm/ADT/Optional.h
+++ b/llvm/include/llvm/ADT/Optional.h
@@ -270,7 +270,9 @@ template <typename T> class Optional {
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 @@ template <typename T> class Optional {
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()); }
More information about the llvm-commits
mailing list