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.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@291995 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/__config b/include/__config
index 8b7897d..118e3bd 100644
--- a/include/__config
+++ b/include/__config
@@ -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 @@
 #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 @@
 
 #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 @@
 #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
diff --git a/test/support/test_macros.h b/test/support/test_macros.h
index 40d366a..f1a0bdd 100644
--- a/test/support/test_macros.h
+++ b/test/support/test_macros.h
@@ -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 @@
 #endif
 #endif
 
+
+#if defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
+
 #endif // SUPPORT_TEST_MACROS_HPP