Skip to content

Commit 21f73d5

Browse files
committed
[libc++] Remove workaround for C11 features on compilers that don't support using_if_exists
Instead of carrying around #ifdefs to determine whether those functions are available on the platform, unconditionally use the using_if_exists attribute to import it into namespace std only when available. That was the purpose of this attribute from the start. This change means that trying to use libc++ with an old SDK (or on an old platform for platforms that ship system headers in /usr/include) will require a recent Clang that supports the using_if_exists attribute. When using an older Clang or GCC, the underlying platform has to support a C11 standard library. Differential Revision: https://reviews.llvm.org/D108203
1 parent 611469c commit 21f73d5

File tree

3 files changed

+4
-87
lines changed

3 files changed

+4
-87
lines changed

libcxx/include/__config

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,6 @@
294294
# define _LIBCPP_HAS_BITSCAN64
295295
# endif
296296
# define _LIBCPP_HAS_OPEN_WITH_WCHAR
297-
# if defined(_LIBCPP_MSVCRT)
298-
# define _LIBCPP_HAS_QUICK_EXIT
299-
# endif
300297

301298
// Some CRT APIs are unavailable to store apps
302299
# if defined(WINAPI_FAMILY)
@@ -392,72 +389,6 @@
392389
# define _LIBCPP_NO_CFI
393390
#endif
394391

395-
// If the compiler supports using_if_exists, pretend we have those functions and they'll
396-
// be picked up if the C library provides them.
397-
//
398-
// TODO: Once we drop support for Clang 12, we can assume the compiler supports using_if_exists
399-
// for platforms that don't have a conforming C11 library, so we can drop this whole thing.
400-
#if __has_attribute(using_if_exists)
401-
# define _LIBCPP_HAS_TIMESPEC_GET
402-
# define _LIBCPP_HAS_QUICK_EXIT
403-
# define _LIBCPP_HAS_ALIGNED_ALLOC
404-
#else
405-
#if (defined(__ISO_C_VISIBLE) && (__ISO_C_VISIBLE >= 2011)) || __cplusplus >= 201103L
406-
# if defined(__FreeBSD__)
407-
# define _LIBCPP_HAS_ALIGNED_ALLOC
408-
# define _LIBCPP_HAS_QUICK_EXIT
409-
# if __FreeBSD_version >= 1300064 || \
410-
(__FreeBSD_version >= 1201504 && __FreeBSD_version < 1300000)
411-
# define _LIBCPP_HAS_TIMESPEC_GET
412-
# endif
413-
# elif defined(__BIONIC__)
414-
# if __ANDROID_API__ >= 21
415-
# define _LIBCPP_HAS_QUICK_EXIT
416-
# endif
417-
# if __ANDROID_API__ >= 28
418-
# define _LIBCPP_HAS_ALIGNED_ALLOC
419-
# endif
420-
# if __ANDROID_API__ >= 29
421-
# define _LIBCPP_HAS_TIMESPEC_GET
422-
# endif
423-
# elif defined(__Fuchsia__) || defined(__wasi__) || defined(__NetBSD__)
424-
# define _LIBCPP_HAS_ALIGNED_ALLOC
425-
# define _LIBCPP_HAS_QUICK_EXIT
426-
# define _LIBCPP_HAS_TIMESPEC_GET
427-
# elif defined(__OpenBSD__)
428-
# define _LIBCPP_HAS_ALIGNED_ALLOC
429-
# define _LIBCPP_HAS_TIMESPEC_GET
430-
# elif defined(__linux__)
431-
# if !defined(_LIBCPP_HAS_MUSL_LIBC)
432-
# if _LIBCPP_GLIBC_PREREQ(2, 15) || defined(__BIONIC__)
433-
# define _LIBCPP_HAS_QUICK_EXIT
434-
# endif
435-
# if _LIBCPP_GLIBC_PREREQ(2, 17)
436-
# define _LIBCPP_HAS_ALIGNED_ALLOC
437-
# define _LIBCPP_HAS_TIMESPEC_GET
438-
# endif
439-
# else // defined(_LIBCPP_HAS_MUSL_LIBC)
440-
# define _LIBCPP_HAS_ALIGNED_ALLOC
441-
# define _LIBCPP_HAS_QUICK_EXIT
442-
# define _LIBCPP_HAS_TIMESPEC_GET
443-
# endif
444-
# elif defined(_LIBCPP_MSVCRT)
445-
// Using Microsoft's C Runtime library, not MinGW
446-
# define _LIBCPP_HAS_TIMESPEC_GET
447-
# elif defined(__APPLE__)
448-
// timespec_get and aligned_alloc were introduced in macOS 10.15 and
449-
// aligned releases
450-
# if ((defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101500) || \
451-
(defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 130000) || \
452-
(defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ >= 130000) || \
453-
(defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ >= 60000))
454-
# define _LIBCPP_HAS_ALIGNED_ALLOC
455-
# define _LIBCPP_HAS_TIMESPEC_GET
456-
# endif
457-
# endif // __APPLE__
458-
#endif
459-
#endif // __has_attribute(using_if_exists)
460-
461392
#ifndef _LIBCPP_CXX03_LANG
462393
# define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp)
463394
#elif defined(_LIBCPP_COMPILER_CLANG_BASED)

libcxx/include/cstdlib

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,11 @@ using ::mbtowc _LIBCPP_USING_IF_EXISTS;
132132
using ::wctomb _LIBCPP_USING_IF_EXISTS;
133133
using ::mbstowcs _LIBCPP_USING_IF_EXISTS;
134134
using ::wcstombs _LIBCPP_USING_IF_EXISTS;
135-
#if !defined(_LIBCPP_CXX03_LANG) && defined(_LIBCPP_HAS_QUICK_EXIT)
135+
#if !defined(_LIBCPP_CXX03_LANG)
136136
using ::at_quick_exit _LIBCPP_USING_IF_EXISTS;
137137
using ::quick_exit _LIBCPP_USING_IF_EXISTS;
138138
#endif
139-
#if _LIBCPP_STD_VER > 14 && defined(_LIBCPP_HAS_ALIGNED_ALLOC)
139+
#if _LIBCPP_STD_VER > 14
140140
using ::aligned_alloc _LIBCPP_USING_IF_EXISTS;
141141
#endif
142142

libcxx/include/ctime

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,13 @@ int timespec_get( struct timespec *ts, int base); // C++17
5252
# pragma GCC system_header
5353
#endif
5454

55-
// FIXME:
56-
// Apple SDKs don't define ::timespec_get unconditionally in C++ mode. This
57-
// should be fixed in future SDKs, but for the time being we need to avoid
58-
// trying to use that declaration when the SDK doesn't provide it. Note that
59-
// we're detecting this here instead of in <__config> because we can't include
60-
// system headers from <__config>, since it leads to circular module dependencies.
61-
// This is also meant to be a very temporary workaround until the SDKs are fixed.
62-
#if defined(__APPLE__) && !__has_attribute(using_if_exists)
63-
# include <sys/cdefs.h>
64-
# if defined(_LIBCPP_HAS_TIMESPEC_GET) && (__DARWIN_C_LEVEL < __DARWIN_C_FULL)
65-
# define _LIBCPP_HAS_TIMESPEC_GET_NOT_ACTUALLY_PROVIDED
66-
# endif
67-
#endif
68-
6955
_LIBCPP_BEGIN_NAMESPACE_STD
7056

7157
using ::clock_t _LIBCPP_USING_IF_EXISTS;
7258
using ::size_t _LIBCPP_USING_IF_EXISTS;
7359
using ::time_t _LIBCPP_USING_IF_EXISTS;
7460
using ::tm _LIBCPP_USING_IF_EXISTS;
75-
#if _LIBCPP_STD_VER > 14 && defined(_LIBCPP_HAS_TIMESPEC_GET)
61+
#if _LIBCPP_STD_VER > 14
7662
using ::timespec _LIBCPP_USING_IF_EXISTS;
7763
#endif
7864
using ::clock _LIBCPP_USING_IF_EXISTS;
@@ -84,7 +70,7 @@ using ::ctime _LIBCPP_USING_IF_EXISTS;
8470
using ::gmtime _LIBCPP_USING_IF_EXISTS;
8571
using ::localtime _LIBCPP_USING_IF_EXISTS;
8672
using ::strftime _LIBCPP_USING_IF_EXISTS;
87-
#if _LIBCPP_STD_VER > 14 && defined(_LIBCPP_HAS_TIMESPEC_GET) && !defined(_LIBCPP_HAS_TIMESPEC_GET_NOT_ACTUALLY_PROVIDED)
73+
#if _LIBCPP_STD_VER > 14
8874
using ::timespec_get _LIBCPP_USING_IF_EXISTS;
8975
#endif
9076

0 commit comments

Comments
 (0)