Skip to content

Commit 7bb6185

Browse files
committed
Shims: make the __swift_ssize_t handling more portable
Unfortunately, `cl` does not support C11. Guard the `_Generic` approach and in C++ mode use `std::make_signed`. Thanks to Jordan Rose for the reminder about the type_traits helper!
1 parent 611b0c9 commit 7bb6185

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

stdlib/public/SwiftShims/SwiftStddef.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,18 @@ typedef __SIZE_TYPE__ __swift_size_t;
2929
#endif
3030

3131
// This selects the signed equivalent of the unsigned type chosen for size_t.
32+
#if __STDC_VERSION__-0 >= 201112l
3233
typedef __typeof__(_Generic((__swift_size_t)0, \
3334
unsigned long long int : (long long int)0, \
3435
unsigned long int : (long int)0, \
3536
unsigned int : (int)0, \
3637
unsigned short : (short)0, \
3738
unsigned char : (signed char)0)) __swift_ssize_t;
39+
#elif defined(__cplusplus)
40+
#include <type_traits>
41+
using __swift_ssize_t = std::make_signed<__swift_size_t>::type;
42+
#else
43+
#error "do not have __swift_ssize_t defined"
44+
#endif
3845

3946
#endif // SWIFT_STDLIB_SHIMS_SWIFT_STDDEF_H

0 commit comments

Comments
 (0)