about summary refs log tree commit diff
path: root/include/features.h
diff options
context:
space:
mode:
authorZack Weinberg <zackw@panix.com>2016-04-28 11:07:58 -0400
committerZack Weinberg <zackw@panix.com>2016-08-03 14:03:46 -0400
commitcab4d74b01320670f57dcf356ff89256f4d2fc12 (patch)
tree2a043314a5c820767e04a810eff4ecbad70a5a49 /include/features.h
parentbf91be88ea90c1ea888d5646270d66363389ce96 (diff)
downloadglibc-cab4d74b01320670f57dcf356ff89256f4d2fc12.tar.gz
glibc-cab4d74b01320670f57dcf356ff89256f4d2fc12.tar.xz
glibc-cab4d74b01320670f57dcf356ff89256f4d2fc12.zip
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.
Diffstat (limited to 'include/features.h')
-rw-r--r--include/features.h19
1 files changed, 15 insertions, 4 deletions
diff --git a/include/features.h b/include/features.h
index f2cd148fa4..554c5c888a 100644
--- a/include/features.h
+++ b/include/features.h
@@ -138,13 +138,13 @@
 # define __KERNEL_STRICT_NAMES
 #endif
 
-/* Convenience macros to test the versions of glibc and gcc.
-   Use them like this:
+/* Convenience macro to test the version of gcc.
+   Use like this:
    #if __GNUC_PREREQ (2,8)
    ... code requiring gcc 2.8 or later ...
    #endif
-   Note - they won't work for gcc1 or glibc1, since the _MINOR macros
-   were not defined then.  */
+   Note: only works for GCC 2.0 and later, because __GNUC_MINOR__ was
+   added in 2.0.  */
 #if defined __GNUC__ && defined __GNUC_MINOR__
 # define __GNUC_PREREQ(maj, min) \
 	((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
@@ -152,6 +152,17 @@
 # define __GNUC_PREREQ(maj, min) 0
 #endif
 
+/* Similarly for clang.  Features added to GCC after version 4.2 may
+   or may not also be available in clang, and clang's definitions of
+   __GNUC(_MINOR)__ are fixed at 4 and 2 respectively.  Not all such
+   features can be queried via __has_extension/__has_feature.  */
+#if defined __clang_major__ && defined __clang_minor__
+# define __glibc_clang_prereq(maj, min) \
+  ((__clang_major__ << 16) + __clang_minor__ >= ((maj) << 16) + (min))
+#else
+# define __glibc_clang_prereq(maj, min) 0
+#endif
+
 /* Whether to use feature set F.  */
 #define __GLIBC_USE(F)	__GLIBC_USE_ ## F