[PATCH] D94219: Change the LLVM_ATTRIBUTE_DEPRECATED macro to use C++14 attribute.

Christian Sigg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 7 00:59:52 PST 2021


csigg created this revision.
Herald added subscribers: dexonsmith, sanjoy.google.
csigg requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

C++14 attributes are superior because they can be applied to functions with inline definition and the syntax is cleaner.

I intend to convert all uses and then remove the macro.

One issue that might hold back switching uses to C++14  attributes is that 
clang-format does not understand attributes yet, so formatted code will look like:

  template <typename T>
  [[deprecated("blah blah")]] void foo() {
    ...
  }

Putting long attributes on a separate line would be prettier.
See https://stackoverflow.com/questions/45740466/clang-format-setting-to-control-c-attributes

AttributeMacros probably won't help because it can't match the custom message.
https://clang.llvm.org/docs/ClangFormatStyleOptions.html


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94219

Files:
  llvm/include/llvm/Support/Compiler.h


Index: llvm/include/llvm/Support/Compiler.h
===================================================================
--- llvm/include/llvm/Support/Compiler.h
+++ llvm/include/llvm/Support/Compiler.h
@@ -314,19 +314,9 @@
 #endif
 
 // LLVM_ATTRIBUTE_DEPRECATED(decl, "message")
-#if __has_feature(attribute_deprecated_with_message)
-# define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \
-  decl __attribute__((deprecated(message)))
-#elif defined(__GNUC__)
-# define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \
-  decl __attribute__((deprecated))
-#elif defined(_MSC_VER)
-# define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \
-  __declspec(deprecated(message)) decl
-#else
-# define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \
-  decl
-#endif
+// This macro will be removed.
+// Use C++14's attribute instead: [[deprecated("message")]]
+#define LLVM_ATTRIBUTE_DEPRECATED(decl, message) [[deprecated(message)]] decl
 
 /// LLVM_BUILTIN_UNREACHABLE - On compilers which support it, expands
 /// to an expression which states that it is undefined behavior for the


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94219.315066.patch
Type: text/x-patch
Size: 1050 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210107/edbe6d0b/attachment.bin>


More information about the llvm-commits mailing list