Mark ABSL_DEPRECATED() as [[deprecated]] PiperOrigin-RevId: 985436747 Change-Id: I845e5cf76a90ad029b46c1e364afe3b01426e0eb
diff --git a/absl/base/attributes.h b/absl/base/attributes.h index da12f1f..596fdbb 100644 --- a/absl/base/attributes.h +++ b/absl/base/attributes.h
@@ -646,8 +646,7 @@ // declarations. The macro argument is used as a custom diagnostic message (e.g. // suggestion of a better alternative). // -// For code or headers that are assured to only build with C++14 and up, prefer -// just using the standard `[[deprecated("message")]]` directly over this macro. +// Deprecated: Use the standard `[[deprecated("message")]]` macro instead. // // Examples: // @@ -668,7 +667,25 @@ // turns this warning off by default, instead relying on clang-tidy to report // new uses of deprecated code. #if ABSL_HAVE_ATTRIBUTE(deprecated) +#if defined(__cplusplus) && defined(__clang__) && \ + ABSL_HAVE_ATTRIBUTE(diagnose_if) && !defined(SWIG) +struct [[deprecated( + "Use [[deprecated(...)]] instead.")]] _absl_deprecated_macro; +// Trick: We use __attribute__((diagnose_if(...))) to refer to our own +// deprecated symbol, which then causes a deprecation message to be emitted when +// the macro is used. Since diagnose_if() isn't valid on every declaration, we +// also suppress the warning regarding that. +#define ABSL_DEPRECATED(message) \ + _Pragma("clang diagnostic push") /* */ \ + _Pragma("clang diagnostic ignored \"-Wignored-attributes\"") \ + __attribute__((diagnose_if( \ + sizeof(_absl_deprecated_macro*) == 0, "", \ + "warning"))) /* */ \ + _Pragma("clang diagnostic pop") /* */ \ + __attribute__((deprecated(message))) +#else #define ABSL_DEPRECATED(message) __attribute__((deprecated(message))) +#endif #else #define ABSL_DEPRECATED(message) #endif @@ -678,7 +695,7 @@ // deprecated code can be surrounded with these directives to achieve that // result. // -// class ABSL_DEPRECATED("Use Bar instead") Foo; +// class [[deprecated("Use Bar instead")]] Foo; // // ABSL_INTERNAL_DISABLE_DEPRECATED_DECLARATION_WARNING // Baz ComputeBazFromFoo(Foo f);