This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH 1/2] Add __clang_has_extension to sys/cdefs.h.
- From: Zack Weinberg <zackw at panix dot com>
- To: libc-alpha at sourceware dot org
- Date: Fri, 22 Apr 2016 19:05:34 -0400
- Subject: [PATCH 1/2] Add __clang_has_extension to sys/cdefs.h.
- Authentication-results: sourceware.org; auth=none
- References: <cover dot 1461444595 dot git dot zackw at panix dot com>
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