[libcxx] r291995 - Use __is_identifier to detect Clang extensions instead of __has_extension.
Eric Fiselier via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 13 20:27:58 PST 2017
Author: ericwf
Date: Fri Jan 13 22:27:58 2017
New Revision: 291995
URL: http://llvm.org/viewvc/llvm-project?rev=291995&view=rev
Log:
Use __is_identifier to detect Clang extensions instead of __has_extension.
When -pedantic-errors is specified `__has_extension(<feature>)` is always
false when it would otherwise be true. This causes C++03 <atomic> to break
along with other issues.
This patch avoids the above problem by using __is_identifier(...) instead since
it is not affected by -pedantic-errors. For example instead of checking for
__has_extension(c_atomics) we now check `!__is_identifier(_Atomic)`, which
is only true when _Atomic is not a keyword provided by the compiler.
This patch applies similar changes to the detection logic for __decltype and
__nullptr as well.
Note that it does not apply this change to the C++03
`static_assert` macro since -Wc11-extensions warnings generated by expanding
that macro will appear in user code, and will not be suppressed as part of a
system header.
Modified:
libcxx/trunk/include/__config
libcxx/trunk/test/support/test_macros.h
Modified: libcxx/trunk/include/__config
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=291995&r1=291994&r2=291995&view=diff
==============================================================================
--- libcxx/trunk/include/__config (original)
+++ libcxx/trunk/include/__config Fri Jan 13 22:27:58 2017
@@ -101,6 +101,8 @@
#define __is_identifier(__x) 1
#endif
+#define __has_keyword(__x) !(__is_identifier(__x))
+
#if defined(__clang__)
#define _LIBCPP_COMPILER_CLANG
#elif defined(__GNUC__)
@@ -290,7 +292,7 @@ typedef __char32_t char32_t;
#endif
#if !(__has_feature(cxx_nullptr))
-# if __has_extension(cxx_nullptr) && defined(_LIBCPP_ABI_ALWAYS_USE_CXX11_NULLPTR)
+# if (__has_extension(cxx_nullptr) || __has_keyword(__nullptr)) && defined(_LIBCPP_ABI_ALWAYS_USE_CXX11_NULLPTR)
# define nullptr __nullptr
# else
# define _LIBCPP_HAS_NO_NULLPTR
@@ -741,7 +743,7 @@ template <unsigned> struct __static_asse
#ifdef _LIBCPP_HAS_NO_DECLTYPE
// GCC 4.6 provides __decltype in all standard modes.
-#if !__is_identifier(__decltype) || _GNUC_VER >= 406
+#if __has_keyword(__decltype) || _GNUC_VER >= 406
# define decltype(__x) __decltype(__x)
#else
# define decltype(__x) __typeof__(__x)
@@ -970,7 +972,7 @@ _LIBCPP_FUNC_VIS extern "C" void __sanit
#define _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS
#endif
-#if __has_feature(cxx_atomic) || __has_extension(c_atomic)
+#if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic)
#define _LIBCPP_HAS_C_ATOMIC_IMP
#elif _GNUC_VER > 407
#define _LIBCPP_HAS_GCC_ATOMIC_IMP
Modified: libcxx/trunk/test/support/test_macros.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/support/test_macros.h?rev=291995&r1=291994&r2=291995&view=diff
==============================================================================
--- libcxx/trunk/test/support/test_macros.h (original)
+++ libcxx/trunk/test/support/test_macros.h Fri Jan 13 22:27:58 2017
@@ -13,6 +13,11 @@
#include <ciso646> // Get STL specific macros like _LIBCPP_VERSION
+#if defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wvariadic-macros"
+#endif
+
#define TEST_CONCAT1(X, Y) X##Y
#define TEST_CONCAT(X, Y) TEST_CONCAT1(X, Y)
@@ -177,4 +182,9 @@ struct is_same<T, T> { enum {value = 1};
#endif
#endif
+
+#if defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
+
#endif // SUPPORT_TEST_MACROS_HPP
More information about the cfe-commits
mailing list