From ee187e247bc2c7b97eb345e1de7f5ccf151e24e5 Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Sat, 13 Jun 2015 07:08:02 +0000 Subject: [PATCH] [libcxx] Fix detection of __is_final. Summary: Currently we only enable the use of __is_final(...) with Clang. GCC also provides __is_final(...) since 4.7 in all standard modes. This patch creates the macro _LIBCPP_HAS_IS_FINAL to note the availability of `__is_final`. Reviewers: danalbert, mclow.lists Reviewed By: mclow.lists Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D8795 llvm-svn: 239664 --- libcxx/include/__config | 22 ++++++++++++---------- libcxx/include/exception | 8 ++------ libcxx/include/ext/hash_map | 15 +++++++-------- libcxx/include/map | 7 +++---- libcxx/include/memory | 9 ++------- libcxx/include/tuple | 6 ++---- libcxx/include/type_traits | 12 ++++++++++-- libcxx/include/unordered_map | 12 ++++-------- 8 files changed, 42 insertions(+), 49 deletions(-) diff --git a/libcxx/include/__config b/libcxx/include/__config index 00efda2..9ab02e3 100644 --- a/libcxx/include/__config +++ b/libcxx/include/__config @@ -77,10 +77,8 @@ #ifdef _WIN32 # define _LIBCPP_LITTLE_ENDIAN 1 # define _LIBCPP_BIG_ENDIAN 0 -// Compiler intrinsics (GCC or MSVC) -# if defined(__clang__) \ - || (defined(_MSC_VER) && _MSC_VER >= 1400) \ - || (defined(__GNUC__) && _GNUC_VER > 403) +// Compiler intrinsics (MSVC) +#if defined(_MSC_VER) && _MSC_VER >= 1400 # define _LIBCPP_HAS_IS_BASE_OF # endif # if defined(_MSC_VER) && !defined(__clang__) @@ -95,12 +93,6 @@ # endif #endif // _WIN32 -#ifdef __linux__ -# if defined(__GNUC__) && _GNUC_VER >= 403 -# define _LIBCPP_HAS_IS_BASE_OF -# endif -#endif - #ifdef __sun__ # include # ifdef _LITTLE_ENDIAN @@ -320,6 +312,10 @@ typedef __char32_t char32_t; # define _LIBCPP_HAS_IS_BASE_OF #endif +#if __has_feature(is_final) +# define _LIBCPP_HAS_IS_FINAL +#endif + // Objective-C++ features (opt-in) #if __has_feature(objc_arc) #define _LIBCPP_HAS_OBJC_ARC @@ -403,6 +399,11 @@ namespace std { #if _GNUC_VER >= 407 #define _LIBCPP_UNDERLYING_TYPE(T) __underlying_type(T) #define _LIBCPP_IS_LITERAL(T) __is_literal_type(T) +#define _LIBCPP_HAS_IS_FINAL +#endif + +#if defined(__GNUC__) && _GNUC_VER >= 403 +# define _LIBCPP_HAS_IS_BASE_OF #endif #if !__EXCEPTIONS @@ -537,6 +538,7 @@ namespace std { #define _LIBCPP_HAS_NO_NULLPTR #define _LIBCPP_HAS_NO_UNICODE_CHARS #define _LIBCPP_HAS_IS_BASE_OF +#define _LIBCPP_HAS_IS_FINAL #define _LIBCPP_HAS_NO_VARIABLE_TEMPLATES #if defined(_AIX) diff --git a/libcxx/include/exception b/libcxx/include/exception index 39d251e..5a905e7 100644 --- a/libcxx/include/exception +++ b/libcxx/include/exception @@ -195,9 +195,7 @@ void throw_with_nested(_Tp&& __t, typename enable_if< is_class::type>::value && !is_base_of::type>::value -#if _LIBCPP_STD_VER > 11 && __has_feature(is_final) - && !is_final::type>::value -#endif + && !__libcpp_is_final::type>::value >::type* = 0) #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES throw_with_nested (_Tp& __t, typename enable_if< @@ -217,9 +215,7 @@ void throw_with_nested(_Tp&& __t, typename enable_if< !is_class::type>::value || is_base_of::type>::value -#if _LIBCPP_STD_VER > 11 && __has_feature(is_final) - || is_final::type>::value -#endif + || __libcpp_is_final::type>::value >::type* = 0) #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES throw_with_nested (_Tp& __t, typename enable_if< diff --git a/libcxx/include/ext/hash_map b/libcxx/include/ext/hash_map index d8fc1e6..31fcedf 100644 --- a/libcxx/include/ext/hash_map +++ b/libcxx/include/ext/hash_map @@ -203,6 +203,7 @@ template #include <__hash_table> #include #include +#include #include #if __DEPRECATED @@ -213,16 +214,16 @@ template #endif #endif +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header +#endif namespace __gnu_cxx { using namespace std; -template ::value -#if __has_feature(is_final) - && !__is_final(_Hash) -#endif +template ::value && !__libcpp_is_final<_Hash>::value > class __hash_map_hasher : private _Hash @@ -255,10 +256,8 @@ public: {return __hash_(__x);} }; -template ::value -#if __has_feature(is_final) - && !__is_final(_Pred) -#endif +template ::value && !__libcpp_is_final<_Pred>::value > class __hash_map_equal : private _Pred diff --git a/libcxx/include/map b/libcxx/include/map index 4c79662..14eb4eb 100644 --- a/libcxx/include/map +++ b/libcxx/include/map @@ -428,6 +428,7 @@ swap(multimap& x, #include #include #include +#include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header @@ -435,10 +436,8 @@ swap(multimap& x, _LIBCPP_BEGIN_NAMESPACE_STD -template ::value -#if __has_feature(is_final) - && !__is_final(_Compare) -#endif +template ::value && !__libcpp_is_final<_Compare>::value > class __map_value_compare : private _Compare diff --git a/libcxx/include/memory b/libcxx/include/memory index dc5902d..03897b1 100644 --- a/libcxx/include/memory +++ b/libcxx/include/memory @@ -1982,14 +1982,9 @@ public: template ::type, typename remove_cv<_T2>::type>::value, bool = is_empty<_T1>::value -#if __has_feature(is_final) - && !__is_final(_T1) -#endif - , + && !__libcpp_is_final<_T1>::value, bool = is_empty<_T2>::value -#if __has_feature(is_final) - && !__is_final(_T2) -#endif + && !__libcpp_is_final<_T2>::value > struct __libcpp_compressed_pair_switch; diff --git a/libcxx/include/tuple b/libcxx/include/tuple index d838a95..3a22aa5 100644 --- a/libcxx/include/tuple +++ b/libcxx/include/tuple @@ -161,10 +161,8 @@ using tuple_element_t = typename tuple_element <_Ip, _Tp...>::type; // __tuple_leaf -template ::value -#if __has_feature(is_final) - && !__is_final(_Hp) -#endif +template ::value && !__libcpp_is_final<_Hp>::value > class __tuple_leaf; diff --git a/libcxx/include/type_traits b/libcxx/include/type_traits index 531caf0..5965b79 100644 --- a/libcxx/include/type_traits +++ b/libcxx/include/type_traits @@ -803,8 +803,16 @@ template struct _LIBCPP_TYPE_VIS_ONLY is_abstract : public __libcpp_ // is_final -#if _LIBCPP_STD_VER > 11 && __has_feature(is_final) -template struct _LIBCPP_TYPE_VIS_ONLY +#if defined(_LIBCPP_HAS_IS_FINAL) +template struct _LIBCPP_TYPE_VIS_ONLY +__libcpp_is_final : public integral_constant {}; +#else +template struct _LIBCPP_TYPE_VIS_ONLY +__libcpp_is_final : public false_type {}; +#endif + +#if defined(_LIBCPP_HAS_IS_FINAL) && _LIBCPP_STD_VER > 11 +template struct _LIBCPP_TYPE_VIS_ONLY is_final : public integral_constant {}; #endif diff --git a/libcxx/include/unordered_map b/libcxx/include/unordered_map index 6cd82f5..15d5176 100644 --- a/libcxx/include/unordered_map +++ b/libcxx/include/unordered_map @@ -361,10 +361,8 @@ template _LIBCPP_BEGIN_NAMESPACE_STD -template ::value -#if __has_feature(is_final) - && !__is_final(_Hash) -#endif +template ::value && !__libcpp_is_final<_Hash>::value > class __unordered_map_hasher : private _Hash @@ -412,10 +410,8 @@ public: {return __hash_(__x);} }; -template ::value -#if __has_feature(is_final) - && !__is_final(_Pred) -#endif +template ::value && !__libcpp_is_final<_Pred>::value > class __unordered_map_equal : private _Pred -- 2.7.4