Skip to content

Commit a4cb5ae

Browse files
committed
[libc++] Remove some workarounds for unsupported GCC and Clang versions
There is a lot more we can do, in particular in <type_traits>, but this removes some workarounds that were gated on checking a specific compiler version. Differential Revision: https://reviews.llvm.org/D108923
1 parent 9d7ae0a commit a4cb5ae

File tree

10 files changed

+9
-258
lines changed

10 files changed

+9
-258
lines changed

libcxx/include/__config

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,6 @@
2424

2525
#ifdef __cplusplus
2626

27-
#ifdef __GNUC__
28-
# define _GNUC_VER (__GNUC__ * 100 + __GNUC_MINOR__)
29-
// The _GNUC_VER_NEW macro better represents the new GCC versioning scheme
30-
// introduced in GCC 5.0.
31-
# define _GNUC_VER_NEW (_GNUC_VER * 10 + __GNUC_PATCHLEVEL__)
32-
#else
33-
# define _GNUC_VER 0
34-
# define _GNUC_VER_NEW 0
35-
#endif
36-
3727
#define _LIBCPP_VERSION 14000
3828

3929
#ifndef _LIBCPP_ABI_VERSION
@@ -509,22 +499,8 @@ typedef __char32_t char32_t;
509499
#define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow")))
510500
#endif
511501

512-
#if __has_builtin(__builtin_launder)
513-
#define _LIBCPP_COMPILER_HAS_BUILTIN_LAUNDER
514-
#endif
515-
516-
#if __has_builtin(__builtin_constant_p)
517-
#define _LIBCPP_COMPILER_HAS_BUILTIN_CONSTANT_P
518-
#endif
519-
520502
#define _LIBCPP_ALWAYS_INLINE __attribute__ ((__always_inline__))
521503

522-
// Literal operators ""d and ""y are supported starting with LLVM Clang 8 and AppleClang 10.0.1
523-
#if (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER < 800) || \
524-
(defined(_LIBCPP_APPLE_CLANG_VER) && _LIBCPP_APPLE_CLANG_VER < 1001)
525-
#define _LIBCPP_HAS_NO_CXX20_CHRONO_LITERALS
526-
#endif
527-
528504
#define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
529505

530506
#elif defined(_LIBCPP_COMPILER_GCC)
@@ -547,11 +523,6 @@ typedef __char32_t char32_t;
547523
#define _LIBCPP_HAS_NO_ASAN
548524
#endif
549525

550-
#if _GNUC_VER >= 700
551-
#define _LIBCPP_COMPILER_HAS_BUILTIN_LAUNDER
552-
#define _LIBCPP_COMPILER_HAS_BUILTIN_CONSTANT_P
553-
#endif
554-
555526
#define _LIBCPP_ALWAYS_INLINE __attribute__ ((__always_inline__))
556527

557528
#define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
@@ -1275,7 +1246,7 @@ extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
12751246
# define _LIBCPP_FALLTHROUGH() [[fallthrough]]
12761247
#elif __has_cpp_attribute(clang::fallthrough)
12771248
# define _LIBCPP_FALLTHROUGH() [[clang::fallthrough]]
1278-
#elif __has_attribute(fallthrough) || _GNUC_VER >= 700
1249+
#elif __has_attribute(__fallthrough__)
12791250
# define _LIBCPP_FALLTHROUGH() __attribute__((__fallthrough__))
12801251
#else
12811252
# define _LIBCPP_FALLTHROUGH() ((void)0)
@@ -1380,12 +1351,6 @@ extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
13801351
# define _LIBCPP_FOPEN_CLOEXEC_MODE
13811352
#endif
13821353

1383-
#ifdef _LIBCPP_COMPILER_HAS_BUILTIN_CONSTANT_P
1384-
#define _LIBCPP_BUILTIN_CONSTANT_P(x) __builtin_constant_p(x)
1385-
#else
1386-
#define _LIBCPP_BUILTIN_CONSTANT_P(x) false
1387-
#endif
1388-
13891354
// Support for _FILE_OFFSET_BITS=64 landed gradually in Android, so the full set
13901355
// of functions used in cstdio may not be available for low API levels when
13911356
// using 64-bit file offsets on LP32.

libcxx/include/atomic

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,11 +1496,8 @@ template <typename _Tp,
14961496
typename _Base = __cxx_atomic_base_impl<_Tp> >
14971497
#endif //_LIBCPP_ATOMIC_ONLY_USE_BUILTINS
14981498
struct __cxx_atomic_impl : public _Base {
1499-
1500-
#if _GNUC_VER >= 501
15011499
static_assert(is_trivially_copyable<_Tp>::value,
15021500
"std::atomic<Tp> requires that 'Tp' be a trivially copyable type");
1503-
#endif
15041501

15051502
_LIBCPP_INLINE_VISIBILITY __cxx_atomic_impl() _NOEXCEPT _LIBCPP_DEFAULT
15061503
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR explicit __cxx_atomic_impl(_Tp value) _NOEXCEPT

libcxx/include/chrono

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2907,7 +2907,7 @@ inline namespace literals
29072907
return chrono::duration<long double, nano> (__ns);
29082908
}
29092909

2910-
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_CHRONO_LITERALS)
2910+
#if _LIBCPP_STD_VER > 17
29112911
constexpr chrono::day operator ""d(unsigned long long __d) noexcept
29122912
{
29132913
return chrono::day(static_cast<unsigned>(__d));

libcxx/include/new

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,7 @@ _LIBCPP_CONSTEXPR _Tp* __launder(_Tp* __p) _NOEXCEPT
337337
{
338338
static_assert (!(is_function<_Tp>::value), "can't launder functions" );
339339
static_assert (!(is_same<void, typename remove_cv<_Tp>::type>::value), "can't launder cv-void" );
340-
#ifdef _LIBCPP_COMPILER_HAS_BUILTIN_LAUNDER
341340
return __builtin_launder(__p);
342-
#else
343-
return __p;
344-
#endif
345341
}
346342

347343
#if _LIBCPP_STD_VER > 14

libcxx/include/string

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2373,7 +2373,7 @@ basic_string<_CharT, _Traits, _Allocator>&
23732373
basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
23742374
{
23752375
_LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
2376-
return (_LIBCPP_BUILTIN_CONSTANT_P(__n) && __n < __min_cap)
2376+
return (__builtin_constant_p(__n) && __n < __min_cap)
23772377
? __assign_short(__s, __n)
23782378
: __assign_external(__s, __n);
23792379
}
@@ -2578,7 +2578,7 @@ basic_string<_CharT, _Traits, _Allocator>&
25782578
basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
25792579
{
25802580
_LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
2581-
return _LIBCPP_BUILTIN_CONSTANT_P(*__s)
2581+
return __builtin_constant_p(*__s)
25822582
? (traits_type::length(__s) < __min_cap
25832583
? __assign_short(__s, traits_type::length(__s))
25842584
: __assign_external(__s, traits_type::length(__s)))

libcxx/include/type_traits

Lines changed: 2 additions & 195 deletions
Original file line numberDiff line numberDiff line change
@@ -3049,135 +3049,10 @@ struct __member_pointer_class_type<_Ret _ClassType::*> {
30493049

30503050
// template <class T, class... Args> struct is_constructible;
30513051

3052-
#if defined(_LIBCPP_COMPILER_GCC) && _GNUC_VER_NEW >= 10000
3053-
# define _LIBCPP_GCC_SUPPORTS_IS_CONSTRUCTIBLE
3054-
#endif
3055-
3056-
#if !defined(_LIBCPP_CXX03_LANG) && !__has_feature(is_constructible) && !defined(_LIBCPP_GCC_SUPPORTS_IS_CONSTRUCTIBLE)
3057-
3058-
template <class _Tp, class... _Args>
3059-
struct __libcpp_is_constructible;
3060-
3061-
template <class _To, class _From>
3062-
struct __is_invalid_base_to_derived_cast {
3063-
static_assert(is_reference<_To>::value, "Wrong specialization");
3064-
using _RawFrom = __uncvref_t<_From>;
3065-
using _RawTo = __uncvref_t<_To>;
3066-
static const bool value = _And<
3067-
_IsNotSame<_RawFrom, _RawTo>,
3068-
is_base_of<_RawFrom, _RawTo>,
3069-
_Not<__libcpp_is_constructible<_RawTo, _From>>
3070-
>::value;
3071-
};
3072-
3073-
template <class _To, class _From>
3074-
struct __is_invalid_lvalue_to_rvalue_cast : false_type {
3075-
static_assert(is_reference<_To>::value, "Wrong specialization");
3076-
};
3077-
3078-
template <class _ToRef, class _FromRef>
3079-
struct __is_invalid_lvalue_to_rvalue_cast<_ToRef&&, _FromRef&> {
3080-
using _RawFrom = __uncvref_t<_FromRef>;
3081-
using _RawTo = __uncvref_t<_ToRef>;
3082-
static const bool value = _And<
3083-
_Not<is_function<_RawTo>>,
3084-
_Or<
3085-
_IsSame<_RawFrom, _RawTo>,
3086-
is_base_of<_RawTo, _RawFrom>>
3087-
>::value;
3088-
};
3089-
3090-
struct __is_constructible_helper
3091-
{
3092-
template <class _To>
3093-
static void __eat(_To);
3094-
3095-
// This overload is needed to work around a Clang bug that disallows
3096-
// static_cast<T&&>(e) for non-reference-compatible types.
3097-
// Example: static_cast<int&&>(declval<double>());
3098-
// NOTE: The static_cast implementation below is required to support
3099-
// classes with explicit conversion operators.
3100-
template <class _To, class _From,
3101-
class = decltype(__eat<_To>(declval<_From>()))>
3102-
static true_type __test_cast(int);
3103-
3104-
template <class _To, class _From,
3105-
class = decltype(static_cast<_To>(declval<_From>()))>
3106-
static integral_constant<bool,
3107-
!__is_invalid_base_to_derived_cast<_To, _From>::value &&
3108-
!__is_invalid_lvalue_to_rvalue_cast<_To, _From>::value
3109-
> __test_cast(long);
3110-
3111-
template <class, class>
3112-
static false_type __test_cast(...);
3113-
3114-
template <class _Tp, class ..._Args,
3115-
class = decltype(_Tp(declval<_Args>()...))>
3116-
static true_type __test_nary(int);
3117-
template <class _Tp, class...>
3118-
static false_type __test_nary(...);
3119-
3120-
template <class _Tp, class _A0, class = decltype(::new _Tp(declval<_A0>()))>
3121-
static is_destructible<_Tp> __test_unary(int);
3122-
template <class, class>
3123-
static false_type __test_unary(...);
3124-
};
3125-
3126-
template <class _Tp, bool = is_void<_Tp>::value>
3127-
struct __is_default_constructible
3128-
: decltype(__is_constructible_helper::__test_nary<_Tp>(0))
3129-
{};
3130-
3131-
template <class _Tp>
3132-
struct __is_default_constructible<_Tp, true> : false_type {};
3133-
3134-
template <class _Tp>
3135-
struct __is_default_constructible<_Tp[], false> : false_type {};
3136-
3137-
template <class _Tp, size_t _Nx>
3138-
struct __is_default_constructible<_Tp[_Nx], false>
3139-
: __is_default_constructible<typename remove_all_extents<_Tp>::type> {};
3140-
3141-
template <class _Tp, class... _Args>
3142-
struct __libcpp_is_constructible
3143-
{
3144-
static_assert(sizeof...(_Args) > 1, "Wrong specialization");
3145-
typedef decltype(__is_constructible_helper::__test_nary<_Tp, _Args...>(0))
3146-
type;
3147-
};
3148-
3149-
template <class _Tp>
3150-
struct __libcpp_is_constructible<_Tp> : __is_default_constructible<_Tp> {};
3151-
3152-
template <class _Tp, class _A0>
3153-
struct __libcpp_is_constructible<_Tp, _A0>
3154-
: public decltype(__is_constructible_helper::__test_unary<_Tp, _A0>(0))
3155-
{};
3156-
3157-
template <class _Tp, class _A0>
3158-
struct __libcpp_is_constructible<_Tp&, _A0>
3159-
: public decltype(__is_constructible_helper::
3160-
__test_cast<_Tp&, _A0>(0))
3161-
{};
3162-
3163-
template <class _Tp, class _A0>
3164-
struct __libcpp_is_constructible<_Tp&&, _A0>
3165-
: public decltype(__is_constructible_helper::
3166-
__test_cast<_Tp&&, _A0>(0))
3167-
{};
3168-
3169-
#endif
3170-
3171-
#if __has_feature(is_constructible) || defined(_LIBCPP_GCC_SUPPORTS_IS_CONSTRUCTIBLE)
31723052
template <class _Tp, class ..._Args>
31733053
struct _LIBCPP_TEMPLATE_VIS is_constructible
31743054
: public integral_constant<bool, __is_constructible(_Tp, _Args...)>
3175-
{};
3176-
#else
3177-
template <class _Tp, class... _Args>
3178-
struct _LIBCPP_TEMPLATE_VIS is_constructible
3179-
: public __libcpp_is_constructible<_Tp, _Args...>::type {};
3180-
#endif
3055+
{ };
31813056

31823057
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
31833058
template <class _Tp, class ..._Args>
@@ -3250,53 +3125,12 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_move_constructible_v
32503125

32513126
// is_trivially_constructible
32523127

3253-
#if __has_feature(is_trivially_constructible) || _GNUC_VER >= 501
3254-
32553128
template <class _Tp, class... _Args>
32563129
struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible
32573130
: integral_constant<bool, __is_trivially_constructible(_Tp, _Args...)>
32583131
{
32593132
};
32603133

3261-
#else // !__has_feature(is_trivially_constructible)
3262-
3263-
template <class _Tp, class... _Args>
3264-
struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible
3265-
: false_type
3266-
{
3267-
};
3268-
3269-
template <class _Tp>
3270-
struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp>
3271-
#if __has_feature(has_trivial_constructor) || defined(_LIBCPP_COMPILER_GCC)
3272-
: integral_constant<bool, __has_trivial_constructor(_Tp)>
3273-
#else
3274-
: integral_constant<bool, is_scalar<_Tp>::value>
3275-
#endif
3276-
{
3277-
};
3278-
3279-
template <class _Tp>
3280-
struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, _Tp&&>
3281-
: integral_constant<bool, is_scalar<_Tp>::value>
3282-
{
3283-
};
3284-
3285-
template <class _Tp>
3286-
struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, const _Tp&>
3287-
: integral_constant<bool, is_scalar<_Tp>::value>
3288-
{
3289-
};
3290-
3291-
template <class _Tp>
3292-
struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, _Tp&>
3293-
: integral_constant<bool, is_scalar<_Tp>::value>
3294-
{
3295-
};
3296-
3297-
#endif // !__has_feature(is_trivially_constructible)
3298-
3299-
33003134
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
33013135
template <class _Tp, class... _Args>
33023136
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_constructible_v
@@ -3341,37 +3175,10 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_move_constructible_v
33413175

33423176
// is_trivially_assignable
33433177

3344-
#if __has_feature(is_trivially_assignable) || _GNUC_VER >= 501
3345-
33463178
template <class _Tp, class _Arg>
33473179
struct is_trivially_assignable
33483180
: integral_constant<bool, __is_trivially_assignable(_Tp, _Arg)>
3349-
{
3350-
};
3351-
3352-
#else // !__has_feature(is_trivially_assignable)
3353-
3354-
template <class _Tp, class _Arg>
3355-
struct is_trivially_assignable
3356-
: public false_type {};
3357-
3358-
template <class _Tp>
3359-
struct is_trivially_assignable<_Tp&, _Tp>
3360-
: integral_constant<bool, is_scalar<_Tp>::value> {};
3361-
3362-
template <class _Tp>
3363-
struct is_trivially_assignable<_Tp&, _Tp&>
3364-
: integral_constant<bool, is_scalar<_Tp>::value> {};
3365-
3366-
template <class _Tp>
3367-
struct is_trivially_assignable<_Tp&, const _Tp&>
3368-
: integral_constant<bool, is_scalar<_Tp>::value> {};
3369-
3370-
template <class _Tp>
3371-
struct is_trivially_assignable<_Tp&, _Tp&&>
3372-
: integral_constant<bool, is_scalar<_Tp>::value> {};
3373-
3374-
#endif // !__has_feature(is_trivially_assignable)
3181+
{ };
33753182

33763183
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
33773184
template <class _Tp, class _Arg>

libcxx/include/variant

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,7 @@ public:
233233

234234
_LIBCPP_BEGIN_NAMESPACE_STD
235235

236-
// TODO: GCC 5 lies about its support for C++17 (it says it supports it but it
237-
// really doesn't). That breaks variant, which uses some C++17 features.
238-
// Remove this once we drop support for GCC 5.
239-
#if _LIBCPP_STD_VER > 14 && !(defined(_LIBCPP_COMPILER_GCC) && _GNUC_VER_NEW < 6000)
236+
#if _LIBCPP_STD_VER > 14
240237

241238
// Light N-dimensional array of function pointers. Used in place of std::array to avoid
242239
// adding a dependency.

libcxx/src/include/atomic_support.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
&& defined(__ATOMIC_ACQ_REL) \
2525
&& defined(__ATOMIC_SEQ_CST)
2626
# define _LIBCPP_HAS_ATOMIC_BUILTINS
27-
#elif !defined(__clang__) && defined(_GNUC_VER) && _GNUC_VER >= 407
27+
#elif defined(_LIBCPP_COMPILER_GCC)
2828
# define _LIBCPP_HAS_ATOMIC_BUILTINS
2929
#endif
3030

0 commit comments

Comments
 (0)