Skip to content

Commit 2be8bdd

Browse files
authored
Basic/type_traits: use __is_identifier for some feature checks
When building on Alpine with Musl `__has_feature(is_trivially_constructible)` does not work, even though `__is_trivially_constructible` is defined and `__has_trivial_constructor` is deprecated. Same for `__is_trivially_destructible` and `__has_trivial_destructor` respectively.
1 parent 700bcb4 commit 2be8bdd

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

include/swift/Basic/type_traits.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
#include <type_traits>
1717
#include "swift/Basic/Compiler.h"
1818

19+
#ifndef __has_keyword
20+
#define __has_keyword(__x) !(__is_identifier(__x))
21+
#endif
22+
1923
#ifndef __has_feature
2024
#define SWIFT_DEFINED_HAS_FEATURE
2125
#define __has_feature(x) 0
@@ -45,7 +49,7 @@ struct IsTriviallyConstructible {
4549
#if defined(_LIBCPP_VERSION) || SWIFT_COMPILER_IS_MSVC
4650
// libc++ and MSVC implement is_trivially_constructible.
4751
static const bool value = std::is_trivially_constructible<T>::value;
48-
#elif __has_feature(is_trivially_constructible)
52+
#elif __has_keyword(__is_trivially_constructible)
4953
static const bool value = __is_trivially_constructible(T);
5054
#elif __has_feature(has_trivial_constructor) || __GNUC__ >= 5
5155
static const bool value = __has_trivial_constructor(T);
@@ -59,7 +63,7 @@ struct IsTriviallyDestructible {
5963
#if defined(_LIBCPP_VERSION) || SWIFT_COMPILER_IS_MSVC
6064
// libc++ and MSVC implement is_trivially_destructible.
6165
static const bool value = std::is_trivially_destructible<T>::value;
62-
#elif __has_feature(is_trivially_destructible)
66+
#elif __has_keyword(__is_trivially_destructible)
6367
static const bool value = __is_trivially_destructible(T);
6468
#elif __has_feature(has_trivial_destructor) || __GNUC__ >= 5
6569
static const bool value = __has_trivial_destructor(T);

0 commit comments

Comments
 (0)