From cab4d74b01320670f57dcf356ff89256f4d2fc12 Mon Sep 17 00:00:00 2001 From: Zack Weinberg Date: Thu, 28 Apr 2016 11:07:58 -0400 Subject: Add utility macros for clang detection, and deprecation with messages. There are three new macros added to features.h and sys/cdefs.h: * __glibc_clang_prereq: just like __GNUC_PREREQ, but for clang. * __glibc_clang_has_extension: wraps clang's intrinsic __has_extension. Writing "#if defined __clang__ && __has_extension (...)" doesn't work, because compilers other than clang will object to the unknown macro __has_extension even though they don't need to evaluate it. Instead, write "#if __glibc_clang_has_extension (...)". * __attribute_deprecated_msg__(msg): like __attribute_deprecated__, but if possible, prints a message. The first two are used to define the third. The third will be used in subsequent patches. * include/features.h (__glibc_clang_prereq): New macro. * misc/sys/cdefs.h (__glibc_clang_has_extension) (__attribute_deprecated_msg__): New macros. --- misc/sys/cdefs.h | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'misc/sys') diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h index a3c2429b32..6e9b8403d7 100644 --- a/misc/sys/cdefs.h +++ b/misc/sys/cdefs.h @@ -77,6 +77,15 @@ #endif /* GCC. */ +/* Compilers that are not clang may object to + #if defined __clang__ && __has_extension(...) + even though they do not need to evaluate the right-hand side of the &&. */ +#if defined __clang__ && defined __has_extension +# define __glibc_clang_has_extension(ext) __has_extension (ext) +#else +# define __glibc_clang_has_extension(ext) 0 +#endif + /* These two macros are not used in glibc anymore. They are kept here only because some other projects expect the macros to be defined. */ #define __P(args) args @@ -249,13 +258,24 @@ # define __attribute_noinline__ /* Ignore */ #endif -/* gcc allows marking deprecated functions. */ +/* Since version 3.2, gcc allows marking deprecated functions. */ #if __GNUC_PREREQ (3,2) # define __attribute_deprecated__ __attribute__ ((__deprecated__)) #else # define __attribute_deprecated__ /* Ignore */ #endif +/* Since version 4.5, gcc also allows one to specify the message printed + when a deprecated function is used. clang claims to be gcc 4.2, but + may also support this feature. */ +#if __GNUC_PREREQ (4,5) || \ + __glibc_clang_has_extension (__attribute_deprecated_with_message__) +# define __attribute_deprecated_msg__(msg) \ + __attribute__ ((__deprecated__ (msg))) +#else +# define __attribute_deprecated_msg__(msg) __attribute_deprecated__ +#endif + /* At some point during the gcc 2.8 development the `format_arg' attribute for functions was introduced. We don't want to use it unconditionally (although this would be possible) since it generates warnings. -- cgit v1.2.3