From 54613ab4d448d5df567ae12451ba37cae73f1ac7 Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Sun, 25 Sep 2016 03:34:28 +0000 Subject: [PATCH] [libc++] Remove various C++03 feature test macros Summary: Libc++ still uses per-feature configuration macros when configuring for C++11. However libc++ requires a feature-complete C++11 compiler so there is no reason to check individual features. This patch starts the process of removing the feature specific macros and replacing their usage with `_LIBCPP_CXX03_LANG`. This patch removes the __config macros: * _LIBCPP_HAS_NO_TRAILING_RETURN * _LIBCPP_HAS_NO_TEMPLATE_ALIASES * _LIBCPP_HAS_NO_ADVANCED_SFINAE * _LIBCPP_HAS_NO_DEFAULT_FUNCTION_TEMPLATE_ARGS * _LIBCPP_HAS_NO_STATIC_ASSERT As a drive I also changed our C++03 static_assert to use _Static_assert if available. I plan to commit this without review if nobody voices an objection. Reviewers: mclow.lists Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D24895 llvm-svn: 282347 --- libcxx/include/__config | 55 ++++------------------ libcxx/include/iterator | 6 +-- libcxx/include/memory | 46 +++++++++--------- libcxx/include/ratio | 24 +++++----- libcxx/include/scoped_allocator | 4 +- libcxx/include/type_traits | 6 +-- .../associative/map/map.cons/copy.pass.cpp | 5 +- .../multimap/multimap.cons/copy.pass.cpp | 5 +- .../multiset/multiset.cons/copy.pass.cpp | 5 +- .../associative/set/set.cons/copy.pass.cpp | 5 +- .../sequences/deque/deque.cons/copy.pass.cpp | 6 +-- .../forwardlist/forwardlist.cons/copy.pass.cpp | 5 +- .../sequences/list/list.cons/copy.pass.cpp | 6 +-- .../unord/unord.map/unord.map.cnstr/copy.pass.cpp | 4 +- .../unord.multimap.cnstr/copy.pass.cpp | 4 +- .../unord.multiset.cnstr/copy.pass.cpp | 4 +- .../unord/unord.set/unord.set.cnstr/copy.pass.cpp | 4 +- .../allocate_hint.pass.cpp | 6 ++- .../allocator.traits.members/construct.pass.cpp | 10 ++-- .../allocator.traits.members/destroy.pass.cpp | 6 ++- .../allocator.traits.members/max_size.pass.cpp | 20 ++++---- .../select_on_container_copy_construction.pass.cpp | 6 ++- .../memory/allocator.traits/rebind_traits.pass.cpp | 8 ++-- .../memory/pointer.traits/rebind.pass.cpp | 4 +- libcxx/test/support/test_allocator.h | 8 ++-- 25 files changed, 113 insertions(+), 149 deletions(-) diff --git a/libcxx/include/__config b/libcxx/include/__config index 56326af..9f90a5b 100644 --- a/libcxx/include/__config +++ b/libcxx/include/__config @@ -68,6 +68,9 @@ #define _LIBCPP_NAMESPACE _LIBCPP_CONCAT(__,_LIBCPP_ABI_VERSION) +#if __cplusplus < 201103L +#define _LIBCPP_CXX03_LANG +#endif #ifndef __has_attribute #define __has_attribute(__x) 0 @@ -229,10 +232,6 @@ # define _ALIGNAS(x) __attribute__((__aligned__(x))) #endif -#if !__has_feature(cxx_alias_templates) -#define _LIBCPP_HAS_NO_TEMPLATE_ALIASES -#endif - #if __cplusplus < 201103L typedef __char16_t char16_t; typedef __char32_t char32_t; @@ -260,10 +259,6 @@ typedef __char32_t char32_t; # define _LIBCPP_NORETURN __attribute__ ((noreturn)) #endif -#if !(__has_feature(cxx_default_function_template_args)) -#define _LIBCPP_HAS_NO_DEFAULT_FUNCTION_TEMPLATE_ARGS -#endif - #if !(__has_feature(cxx_defaulted_functions)) #define _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS #endif // !(__has_feature(cxx_defaulted_functions)) @@ -284,26 +279,14 @@ typedef __char32_t char32_t; #define _LIBCPP_HAS_NO_RVALUE_REFERENCES #endif -#if !(__has_feature(cxx_static_assert)) -#define _LIBCPP_HAS_NO_STATIC_ASSERT -#endif - #if !(__has_feature(cxx_auto_type)) #define _LIBCPP_HAS_NO_AUTO_TYPE #endif -#if !(__has_feature(cxx_access_control_sfinae)) || !__has_feature(cxx_trailing_return) -#define _LIBCPP_HAS_NO_ADVANCED_SFINAE -#endif - #if !(__has_feature(cxx_variadic_templates)) #define _LIBCPP_HAS_NO_VARIADICS #endif -#if !(__has_feature(cxx_trailing_return)) -#define _LIBCPP_HAS_NO_TRAILING_RETURN -#endif - #if !(__has_feature(cxx_generalized_initializers)) #define _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS #endif @@ -428,34 +411,26 @@ namespace std { #endif #ifndef __GXX_EXPERIMENTAL_CXX0X__ - -#define _LIBCPP_HAS_NO_ADVANCED_SFINAE #define _LIBCPP_HAS_NO_DECLTYPE -#define _LIBCPP_HAS_NO_DEFAULT_FUNCTION_TEMPLATE_ARGS #define _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS #define _LIBCPP_HAS_NO_DELETED_FUNCTIONS #define _LIBCPP_HAS_NO_NULLPTR -#define _LIBCPP_HAS_NO_STATIC_ASSERT #define _LIBCPP_HAS_NO_UNICODE_CHARS #define _LIBCPP_HAS_NO_VARIADICS #define _LIBCPP_HAS_NO_RVALUE_REFERENCES #define _LIBCPP_HAS_NO_STRONG_ENUMS -#define _LIBCPP_HAS_NO_TEMPLATE_ALIASES #define _LIBCPP_HAS_NO_NOEXCEPT #else // __GXX_EXPERIMENTAL_CXX0X__ #if _GNUC_VER < 403 -#define _LIBCPP_HAS_NO_DEFAULT_FUNCTION_TEMPLATE_ARGS #define _LIBCPP_HAS_NO_RVALUE_REFERENCES -#define _LIBCPP_HAS_NO_STATIC_ASSERT #endif #if _GNUC_VER < 404 #define _LIBCPP_HAS_NO_DECLTYPE #define _LIBCPP_HAS_NO_DELETED_FUNCTIONS -#define _LIBCPP_HAS_NO_TRAILING_RETURN #define _LIBCPP_HAS_NO_UNICODE_CHARS #define _LIBCPP_HAS_NO_VARIADICS #define _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS @@ -464,11 +439,9 @@ namespace std { #if _GNUC_VER < 406 #define _LIBCPP_HAS_NO_NOEXCEPT #define _LIBCPP_HAS_NO_NULLPTR -#define _LIBCPP_HAS_NO_TEMPLATE_ALIASES #endif #if _GNUC_VER < 407 -#define _LIBCPP_HAS_NO_ADVANCED_SFINAE #define _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS #endif @@ -490,7 +463,6 @@ using namespace _LIBCPP_NAMESPACE __attribute__((__strong__)); #elif defined(_LIBCPP_MSVC) -#define _LIBCPP_HAS_NO_TEMPLATE_ALIASES #define _LIBCPP_HAS_NO_CONSTEXPR #define _LIBCPP_HAS_NO_CXX14_CONSTEXPR #define _LIBCPP_HAS_NO_VARIABLE_TEMPLATES @@ -520,9 +492,6 @@ namespace std { #define _ATTRIBUTE(x) __attribute__((x)) #define _LIBCPP_NORETURN __attribute__((noreturn)) -#define _LIBCPP_HAS_NO_DEFAULT_FUNCTION_TEMPLATE_ARGS -#define _LIBCPP_HAS_NO_TEMPLATE_ALIASES -#define _LIBCPP_HAS_NO_ADVANCED_SFINAE #define _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS #define _LIBCPP_HAS_NO_NOEXCEPT #define _LIBCPP_HAS_NO_NULLPTR @@ -677,8 +646,10 @@ typedef unsigned int char32_t; #define _LIBCPP_HAS_NO_INT128 #endif -#ifdef _LIBCPP_HAS_NO_STATIC_ASSERT - +#ifdef _LIBCPP_CXX03_LANG +# if __has_extension(c_static_assert) +# define static_assert(__b, __m) _Static_assert(__b, __m) +# else extern "C++" { template struct __static_assert_test; template <> struct __static_assert_test {}; @@ -687,8 +658,8 @@ template struct __static_assert_check {}; #define static_assert(__b, __m) \ typedef __static_assert_check)> \ _LIBCPP_CONCAT(__t, __LINE__) - -#endif // _LIBCPP_HAS_NO_STATIC_ASSERT +# endif // __has_extension(c_static_assert) +#endif // _LIBCPP_CXX03_LANG #ifdef _LIBCPP_HAS_NO_DECLTYPE // GCC 4.6 provides __decltype in all standard modes. @@ -934,14 +905,6 @@ extern "C" void __sanitizer_annotate_contiguous_container( #define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK #endif -#if __cplusplus < 201103L -#define _LIBCPP_CXX03_LANG -#else -#if defined(_LIBCPP_HAS_NO_VARIADIC_TEMPLATES) || defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) -#error Libc++ requires a feature complete C++11 compiler in C++11 or greater. -#endif -#endif - #if (defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS) && defined(__clang__) \ && __has_attribute(acquire_capability)) #define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS diff --git a/libcxx/include/iterator b/libcxx/include/iterator index 0caabbb..188a480 100644 --- a/libcxx/include/iterator +++ b/libcxx/include/iterator @@ -1566,7 +1566,7 @@ end(_Tp (&__array)[_Np]) return __array + _Np; } -#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN) +#if !defined(_LIBCPP_CXX03_LANG) template inline _LIBCPP_INLINE_VISIBILITY @@ -1689,7 +1689,7 @@ auto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c)) #endif -#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN) +#else // defined(_LIBCPP_CXX03_LANG) template inline _LIBCPP_INLINE_VISIBILITY @@ -1723,7 +1723,7 @@ end(const _Cp& __c) return __c.end(); } -#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN) +#endif // !defined(_LIBCPP_CXX03_LANG) #if _LIBCPP_STD_VER > 14 template diff --git a/libcxx/include/memory b/libcxx/include/memory index 8cb094e..d5b39cb 100644 --- a/libcxx/include/memory +++ b/libcxx/include/memory @@ -828,7 +828,7 @@ public: template ::value> struct __pointer_traits_rebind { -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#ifndef _LIBCPP_CXX03_LANG typedef typename _Tp::template rebind<_Up> type; #else typedef typename _Tp::template rebind<_Up>::other type; @@ -840,7 +840,7 @@ struct __pointer_traits_rebind template