From 215332ffe75cf16b742e2b74dfefd0592c49eb63 Mon Sep 17 00:00:00 2001 From: Conrad Meyer Date: Sat, 14 Dec 2019 21:52:49 +0000 Subject: [PATCH] cdefs: Add __deprecated(message) function attribute macro The legacy version of GCC4 currently in base does not support the parameterized form of this function attribute, as recent introduced in stdlib.h (r355747). As we have done for other function attributes with similar compatibility problems, add a version-compatibile definition in sys/cdefs.h. Note that Clang defines itself to be GCC 4, so one must check for __clang__ in addition to __GNUC__ version. On legacy GCC 4, the macro expands to just the __deprecated__ attribute; on modern GCC or Clang, the macro expands to the parameterized variant with the message. Ignoring legacy or unsupported compilers, the macro is also beneficial in that it is a bit more ergonomic than the full __attribute__((__deprecated__())) boilerplate. Reported by: CI (but not tinderbox); imp and others Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D22817 --- include/stdlib.h | 2 +- sys/sys/cdefs.h | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/stdlib.h b/include/stdlib.h index 50bda707a0d..e46e473fabc 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -315,7 +315,7 @@ long long /* Deprecated interfaces, to be removed. */ static inline void -__attribute__((__deprecated__("sranddev to be removed in FreeBSD 13"))) +__deprecated("sranddev to be removed in FreeBSD 13") sranddev(void) { } diff --git a/sys/sys/cdefs.h b/sys/sys/cdefs.h index 42734b788b3..381ca43e1d8 100644 --- a/sys/sys/cdefs.h +++ b/sys/sys/cdefs.h @@ -468,6 +468,14 @@ #define __hidden #endif +#if __GNUC__ > 4 || defined(__clang__) +#define __deprecated(m) __attribute__((__deprecated__(m))) +#elif defined(__GNUC__) +#define __deprecated(m) __attribute__((__deprecated__)) +#else +#define __deprecated(m) +#endif + /* * We define this here since , , and * require it.