[llvm] 5512f39 - [ADT] Update Optional Deprecation with fix-it

Nathan James via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 8 02:39:39 PDT 2022


Author: Nathan James
Date: 2022-08-08T10:39:31+01:00
New Revision: 5512f398a039e3ed7df502a0c263a8f366a84a4c

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

LOG: [ADT] Update Optional Deprecation with fix-it

When Optional accessors were deprecated, in D131349,  the standard c++14 style attribute was used.
Clang has a slightly better deprecated attribute that enables simpler migration by embedding fix-its.

Reviewed By: kazu

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

Added: 
    

Modified: 
    llvm/include/llvm/ADT/Optional.h
    llvm/include/llvm/Support/Compiler.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/Optional.h b/llvm/include/llvm/ADT/Optional.h
index 4f9e09837f2fe..09770c4f94a0e 100644
--- a/llvm/include/llvm/ADT/Optional.h
+++ b/llvm/include/llvm/ADT/Optional.h
@@ -92,8 +92,8 @@ class OptionalStorage {
   }
 
   constexpr bool has_value() const noexcept { return hasVal; }
-  [[deprecated("Use has_value instead.")]] constexpr bool
-  hasValue() const noexcept {
+  LLVM_DEPRECATED("Use has_value instead.", "has_value")
+  constexpr bool hasValue() const noexcept {
     return hasVal;
   }
 
@@ -101,7 +101,7 @@ class OptionalStorage {
     assert(hasVal);
     return val;
   }
-  [[deprecated("Use value instead.")]] T &getValue() &noexcept {
+  LLVM_DEPRECATED("Use value instead.", "value") T &getValue() &noexcept {
     assert(hasVal);
     return val;
   }
@@ -109,8 +109,8 @@ class OptionalStorage {
     assert(hasVal);
     return val;
   }
-  [[deprecated("Use value instead.")]] constexpr T const &
-  getValue() const &noexcept {
+  LLVM_DEPRECATED("Use value instead.", "value")
+  constexpr T const &getValue() const &noexcept {
     assert(hasVal);
     return val;
   }
@@ -118,7 +118,7 @@ class OptionalStorage {
     assert(hasVal);
     return std::move(val);
   }
-  [[deprecated("Use value instead.")]] T &&getValue() &&noexcept {
+  LLVM_DEPRECATED("Use value instead.", "value") T &&getValue() &&noexcept {
     assert(hasVal);
     return std::move(val);
   }
@@ -207,8 +207,8 @@ template <typename T> class OptionalStorage<T, true> {
   }
 
   constexpr bool has_value() const noexcept { return hasVal; }
-  [[deprecated("Use has_value instead.")]] constexpr bool
-  hasValue() const noexcept {
+  LLVM_DEPRECATED("Use has_value instead.", "has_value")
+  constexpr bool hasValue() const noexcept {
     return hasVal;
   }
 
@@ -216,7 +216,7 @@ template <typename T> class OptionalStorage<T, true> {
     assert(hasVal);
     return val;
   }
-  [[deprecated("Use value instead.")]] T &getValue() &noexcept {
+  LLVM_DEPRECATED("Use value instead.", "value") T &getValue() &noexcept {
     assert(hasVal);
     return val;
   }
@@ -224,8 +224,8 @@ template <typename T> class OptionalStorage<T, true> {
     assert(hasVal);
     return val;
   }
-  [[deprecated("Use value instead.")]] constexpr T const &
-  getValue() const &noexcept {
+  LLVM_DEPRECATED("Use value instead.", "value")
+  constexpr T const &getValue() const &noexcept {
     assert(hasVal);
     return val;
   }
@@ -233,7 +233,7 @@ template <typename T> class OptionalStorage<T, true> {
     assert(hasVal);
     return std::move(val);
   }
-  [[deprecated("Use value instead.")]] T &&getValue() &&noexcept {
+  LLVM_DEPRECATED("Use value instead.", "value") T &&getValue() &&noexcept {
     assert(hasVal);
     return std::move(val);
   }
@@ -311,17 +311,19 @@ template <typename T> class Optional {
   constexpr const T *getPointer() const { return &Storage.value(); }
   T *getPointer() { return &Storage.value(); }
   constexpr const T &value() const & { return Storage.value(); }
-  [[deprecated("Use value instead.")]] constexpr const T &getValue() const & {
+  LLVM_DEPRECATED("Use value instead.", "value")
+  constexpr const T &getValue() const & {
     return Storage.value();
   }
   T &value() & { return Storage.value(); }
-  [[deprecated("Use value instead.")]] T &getValue() & {
+  LLVM_DEPRECATED("Use value instead.", "value") T &getValue() & {
     return Storage.value();
   }
 
   constexpr explicit operator bool() const { return has_value(); }
   constexpr bool has_value() const { return Storage.has_value(); }
-  [[deprecated("Use has_value instead.")]] constexpr bool hasValue() const {
+  LLVM_DEPRECATED("Use has_value instead.", "has_value")
+  constexpr bool hasValue() const {
     return Storage.has_value();
   }
   constexpr const T *operator->() const { return getPointer(); }
@@ -333,8 +335,8 @@ template <typename T> class Optional {
     return has_value() ? value() : std::forward<U>(alt);
   }
   template <typename U>
-  [[deprecated("Use value_or instead.")]] constexpr T
-  getValueOr(U &&alt) const & {
+  LLVM_DEPRECATED("Use value_or instead.", "value_or")
+  constexpr T getValueOr(U &&alt) const & {
     return has_value() ? value() : std::forward<U>(alt);
   }
 
@@ -347,7 +349,7 @@ template <typename T> class Optional {
   }
 
   T &&value() && { return std::move(Storage.value()); }
-  [[deprecated("Use value instead.")]] T &&getValue() && {
+  LLVM_DEPRECATED("Use value instead.", "value") T &&getValue() && {
     return std::move(Storage.value());
   }
   T &&operator*() && { return std::move(Storage.value()); }
@@ -356,7 +358,8 @@ template <typename T> class Optional {
     return has_value() ? std::move(value()) : std::forward<U>(alt);
   }
   template <typename U>
-  [[deprecated("Use value_or instead.")]] T getValueOr(U &&alt) && {
+  LLVM_DEPRECATED("Use value_or instead.", "value_or")
+  T getValueOr(U &&alt) && {
     return has_value() ? std::move(value()) : std::forward<U>(alt);
   }
 

diff  --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h
index 6708b7cc95cc8..8a79d19e446e9 100644
--- a/llvm/include/llvm/Support/Compiler.h
+++ b/llvm/include/llvm/Support/Compiler.h
@@ -138,6 +138,12 @@
 #define LLVM_ATTRIBUTE_USED
 #endif
 
+#if defined(__clang__)
+#define LLVM_DEPRECATED(MSG, FIX) __attribute__((deprecated(MSG, FIX)))
+#else
+#define LLVM_DEPRECATED(MSG, FIX) [[deprecated(MSG)]]
+#endif
+
 /// LLVM_NODISCARD - Warn if a type or return value is discarded.
 
 // Use the 'nodiscard' attribute in C++17 or newer mode.


        


More information about the llvm-commits mailing list