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.

llvm-svn: 291995
This commit is contained in:
Eric Fiselier 2017-01-14 04:27:58 +00:00
parent 9850210d03
commit 1e33f12a7c
2 changed files with 15 additions and 3 deletions

View File

@ -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_assert_check {};
#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 __sanitizer_annotate_contiguous_container(
#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

View File

@ -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