This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 1/2] Add __clang_has_extension to sys/cdefs.h.


clang provides an intrinsic __has_extension() to #if statements, useful
for feature detection.  Other compilers may throw a syntax error on

    #if defined __clang__ && __has_extension(...)

even though they do not need to evaluate the right-hand side of the
logical AND.  __clang_has_extension(...) therefore expands to
__has_extension(...) when __clang__ is defined, and to 0 otherwise.

	* misc/sys/cdefs.h: New utility macro __clang_has_extension.
---
 misc/sys/cdefs.h | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h
index 7fd4154..b31878b 100644
--- a/misc/sys/cdefs.h
+++ b/misc/sys/cdefs.h
@@ -77,7 +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 &&.  */
+#ifdef __clang__
+# define __clang_has_extension(ext) __has_extension (ext)
+#else
+# define __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
-- 
2.8.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]