2015-05-27 08:28:30 +08:00
|
|
|
// -*- C++ -*-
|
|
|
|
//===---------------------------- test_macros.h ---------------------------===//
|
|
|
|
//
|
2019-01-19 18:56:40 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2015-05-27 08:28:30 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef SUPPORT_TEST_MACROS_HPP
|
|
|
|
#define SUPPORT_TEST_MACROS_HPP
|
|
|
|
|
2019-01-16 10:16:57 +08:00
|
|
|
// Attempt to get STL specific macros like _LIBCPP_VERSION using the most
|
|
|
|
// minimal header possible. If we're testing libc++, we should use `<__config>`.
|
|
|
|
// If <__config> isn't available, fall back to <ciso646>.
|
|
|
|
#ifdef __has_include
|
|
|
|
# if __has_include("<__config>")
|
|
|
|
# include <__config>
|
|
|
|
# define TEST_IMP_INCLUDED_HEADER
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
#ifndef TEST_IMP_INCLUDED_HEADER
|
|
|
|
#include <ciso646>
|
|
|
|
#endif
|
2016-04-29 06:28:23 +08:00
|
|
|
|
2017-01-14 12:27:58 +08:00
|
|
|
#if defined(__GNUC__)
|
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wvariadic-macros"
|
|
|
|
#endif
|
|
|
|
|
2020-03-31 04:24:48 +08:00
|
|
|
#define TEST_STRINGIZE_IMPL(x) #x
|
|
|
|
#define TEST_STRINGIZE(x) TEST_STRINGIZE_IMPL(x)
|
|
|
|
|
2015-05-27 08:28:30 +08:00
|
|
|
#define TEST_CONCAT1(X, Y) X##Y
|
|
|
|
#define TEST_CONCAT(X, Y) TEST_CONCAT1(X, Y)
|
|
|
|
|
2015-07-31 10:24:58 +08:00
|
|
|
#ifdef __has_feature
|
|
|
|
#define TEST_HAS_FEATURE(X) __has_feature(X)
|
|
|
|
#else
|
|
|
|
#define TEST_HAS_FEATURE(X) 0
|
|
|
|
#endif
|
|
|
|
|
2018-07-24 20:40:56 +08:00
|
|
|
#ifndef __has_include
|
|
|
|
#define __has_include(...) 0
|
2016-10-05 05:25:51 +08:00
|
|
|
#endif
|
|
|
|
|
2015-05-27 08:28:30 +08:00
|
|
|
#ifdef __has_extension
|
|
|
|
#define TEST_HAS_EXTENSION(X) __has_extension(X)
|
|
|
|
#else
|
|
|
|
#define TEST_HAS_EXTENSION(X) 0
|
|
|
|
#endif
|
|
|
|
|
2019-12-13 09:48:11 +08:00
|
|
|
#ifdef __has_warning
|
|
|
|
#define TEST_HAS_WARNING(X) __has_warning(X)
|
|
|
|
#else
|
|
|
|
#define TEST_HAS_WARNING(X) 0
|
|
|
|
#endif
|
|
|
|
|
2015-12-10 06:03:06 +08:00
|
|
|
#ifdef __has_builtin
|
|
|
|
#define TEST_HAS_BUILTIN(X) __has_builtin(X)
|
|
|
|
#else
|
|
|
|
#define TEST_HAS_BUILTIN(X) 0
|
|
|
|
#endif
|
2016-08-11 11:13:11 +08:00
|
|
|
#ifdef __is_identifier
|
|
|
|
// '__is_identifier' returns '0' if '__x' is a reserved identifier provided by
|
|
|
|
// the compiler and '1' otherwise.
|
|
|
|
#define TEST_HAS_BUILTIN_IDENTIFIER(X) !__is_identifier(X)
|
|
|
|
#else
|
|
|
|
#define TEST_HAS_BUILTIN_IDENTIFIER(X) 0
|
|
|
|
#endif
|
2015-12-10 06:03:06 +08:00
|
|
|
|
2017-05-11 03:10:49 +08:00
|
|
|
#if defined(__EDG__)
|
|
|
|
# define TEST_COMPILER_EDG
|
|
|
|
#elif defined(__clang__)
|
|
|
|
# define TEST_COMPILER_CLANG
|
2017-03-23 06:41:41 +08:00
|
|
|
# if defined(__apple_build_version__)
|
2017-05-11 03:10:49 +08:00
|
|
|
# define TEST_COMPILER_APPLE_CLANG
|
2017-03-23 06:41:41 +08:00
|
|
|
# endif
|
|
|
|
#elif defined(_MSC_VER)
|
|
|
|
# define TEST_COMPILER_C1XX
|
|
|
|
#elif defined(__GNUC__)
|
|
|
|
# define TEST_COMPILER_GCC
|
|
|
|
#endif
|
|
|
|
|
2016-07-21 06:53:21 +08:00
|
|
|
#if defined(__apple_build_version__)
|
|
|
|
#define TEST_APPLE_CLANG_VER (__clang_major__ * 100) + __clang_minor__
|
|
|
|
#elif defined(__clang_major__)
|
|
|
|
#define TEST_CLANG_VER (__clang_major__ * 100) + __clang_minor__
|
|
|
|
#elif defined(__GNUC__)
|
|
|
|
#define TEST_GCC_VER (__GNUC__ * 100 + __GNUC_MINOR__)
|
2019-01-16 09:37:43 +08:00
|
|
|
#define TEST_GCC_VER_NEW (TEST_GCC_VER * 10 + __GNUC_PATCHLEVEL__)
|
2016-07-21 06:53:21 +08:00
|
|
|
#endif
|
|
|
|
|
2015-05-27 08:28:30 +08:00
|
|
|
/* Make a nice name for the standard version */
|
2016-06-15 05:31:42 +08:00
|
|
|
#ifndef TEST_STD_VER
|
2015-05-27 08:28:30 +08:00
|
|
|
#if __cplusplus <= 199711L
|
|
|
|
# define TEST_STD_VER 3
|
|
|
|
#elif __cplusplus <= 201103L
|
|
|
|
# define TEST_STD_VER 11
|
|
|
|
#elif __cplusplus <= 201402L
|
|
|
|
# define TEST_STD_VER 14
|
2017-07-17 11:02:27 +08:00
|
|
|
#elif __cplusplus <= 201703L
|
|
|
|
# define TEST_STD_VER 17
|
2021-01-07 19:29:04 +08:00
|
|
|
#elif __cplusplus <= 202002L
|
|
|
|
# define TEST_STD_VER 20
|
2015-05-27 08:28:30 +08:00
|
|
|
#else
|
2017-07-17 11:02:27 +08:00
|
|
|
# define TEST_STD_VER 99 // greater than current standard
|
|
|
|
// This is deliberately different than _LIBCPP_STD_VER to discourage matching them up.
|
2015-05-27 08:28:30 +08:00
|
|
|
#endif
|
2016-06-15 05:31:42 +08:00
|
|
|
#endif
|
2015-05-27 08:28:30 +08:00
|
|
|
|
2018-10-25 02:37:42 +08:00
|
|
|
// Attempt to deduce the GLIBC version
|
|
|
|
#if (defined(__has_include) && __has_include(<features.h>)) || \
|
|
|
|
defined(__linux__)
|
2016-09-04 08:48:54 +08:00
|
|
|
#include <features.h>
|
2018-11-02 06:35:51 +08:00
|
|
|
#if defined(__GLIBC_PREREQ)
|
2016-09-04 08:48:54 +08:00
|
|
|
#define TEST_HAS_GLIBC
|
|
|
|
#define TEST_GLIBC_PREREQ(major, minor) __GLIBC_PREREQ(major, minor)
|
|
|
|
#endif
|
2018-11-02 06:35:51 +08:00
|
|
|
#endif
|
2016-09-04 08:48:54 +08:00
|
|
|
|
2015-05-27 08:28:30 +08:00
|
|
|
#if TEST_STD_VER >= 11
|
2020-05-28 04:52:22 +08:00
|
|
|
# define TEST_ALIGNOF(...) alignof(__VA_ARGS__)
|
|
|
|
# define TEST_ALIGNAS(...) alignas(__VA_ARGS__)
|
|
|
|
# define TEST_CONSTEXPR constexpr
|
|
|
|
# define TEST_NOEXCEPT noexcept
|
|
|
|
# define TEST_NOEXCEPT_FALSE noexcept(false)
|
|
|
|
# define TEST_NOEXCEPT_COND(...) noexcept(__VA_ARGS__)
|
2015-05-27 08:28:30 +08:00
|
|
|
#else
|
2020-05-28 04:52:22 +08:00
|
|
|
# if defined(TEST_COMPILER_CLANG)
|
|
|
|
# define TEST_ALIGNOF(...) _Alignof(__VA_ARGS__)
|
|
|
|
# else
|
|
|
|
# define TEST_ALIGNOF(...) __alignof(__VA_ARGS__)
|
|
|
|
# endif
|
|
|
|
# define TEST_ALIGNAS(...) __attribute__((__aligned__(__VA_ARGS__)))
|
|
|
|
# define TEST_CONSTEXPR
|
|
|
|
# define TEST_NOEXCEPT throw()
|
|
|
|
# define TEST_NOEXCEPT_FALSE
|
|
|
|
# define TEST_NOEXCEPT_COND(...)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if TEST_STD_VER >= 17
|
|
|
|
# define TEST_THROW_SPEC(...)
|
|
|
|
#else
|
|
|
|
# define TEST_THROW_SPEC(...) throw(__VA_ARGS__)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if TEST_STD_VER >= 14
|
|
|
|
# define TEST_CONSTEXPR_CXX14 constexpr
|
|
|
|
#else
|
|
|
|
# define TEST_CONSTEXPR_CXX14
|
|
|
|
#endif
|
|
|
|
|
2020-05-22 21:59:48 +08:00
|
|
|
#if TEST_STD_VER >= 17
|
|
|
|
# define TEST_CONSTEXPR_CXX17 constexpr
|
|
|
|
#else
|
|
|
|
# define TEST_CONSTEXPR_CXX17
|
|
|
|
#endif
|
|
|
|
|
2020-05-28 04:52:22 +08:00
|
|
|
#if TEST_STD_VER >= 20
|
|
|
|
# define TEST_CONSTEXPR_CXX20 constexpr
|
2019-01-16 09:51:12 +08:00
|
|
|
#else
|
2020-05-28 04:52:22 +08:00
|
|
|
# define TEST_CONSTEXPR_CXX20
|
2015-05-27 08:28:30 +08:00
|
|
|
#endif
|
|
|
|
|
2019-10-15 08:22:38 +08:00
|
|
|
// Sniff out to see if the underlying C library has C11 features
|
2018-08-16 05:19:08 +08:00
|
|
|
// This is cribbed from __config; but lives here as well because we can't assume libc++
|
2021-04-01 14:29:55 +08:00
|
|
|
#if (defined(__ISO_C_VISIBLE) && (__ISO_C_VISIBLE >= 2011)) || \
|
|
|
|
TEST_STD_VER >= 11
|
2018-08-01 02:23:57 +08:00
|
|
|
# if defined(__FreeBSD__)
|
2021-01-19 21:02:29 +08:00
|
|
|
# if __FreeBSD_version >= 1300064 || \
|
|
|
|
(__FreeBSD_version >= 1201504 && __FreeBSD_version < 1300000)
|
|
|
|
# define TEST_HAS_TIMESPEC_GET
|
|
|
|
# endif
|
Fix _LIBCPP_HAS_ definitions for Android.
Summary:
Android added quick_exit()/at_quick_exit() in API level 21,
aligned_alloc() in API level 28, and timespec_get() in API level 29,
but has the other C11 features at all API levels (since they're basically
just coming from clang directly).
_LIBCPP_HAS_QUICK_EXIT and _LIBCPP_HAS_TIMESPEC_GET already existed,
so we can reuse them. (And use _LIBCPP_HAS_TIMESPEC_GET in a few more
places where _LIBCPP_HAS_C11_FEATURES has been used as a proxy. This
isn't correct for Android.)
_LIBCPP_HAS_ALIGNED_ALLOC is added, to cover aligned_alloc() (obviously).
Add a missing std:: before aligned_alloc in a cstdlib test, and remove a
couple of !defined(_WIN32)s now that we're explicitly testing
TEST_HAS_ALIGNED_ALLOC rather than TEST_HAS_C11_FEATURES.
Reviewers: danalbert, EricWF, mclow.lists
Reviewed By: danalbert
Subscribers: srhines, christof, libcxx-commits
Tags: #libc
Differential Revision: https://reviews.llvm.org/D69929
2019-11-19 04:16:45 +08:00
|
|
|
# define TEST_HAS_ALIGNED_ALLOC
|
2020-07-29 01:41:12 +08:00
|
|
|
# define TEST_HAS_QUICK_EXIT
|
Fix _LIBCPP_HAS_ definitions for Android.
Summary:
Android added quick_exit()/at_quick_exit() in API level 21,
aligned_alloc() in API level 28, and timespec_get() in API level 29,
but has the other C11 features at all API levels (since they're basically
just coming from clang directly).
_LIBCPP_HAS_QUICK_EXIT and _LIBCPP_HAS_TIMESPEC_GET already existed,
so we can reuse them. (And use _LIBCPP_HAS_TIMESPEC_GET in a few more
places where _LIBCPP_HAS_C11_FEATURES has been used as a proxy. This
isn't correct for Android.)
_LIBCPP_HAS_ALIGNED_ALLOC is added, to cover aligned_alloc() (obviously).
Add a missing std:: before aligned_alloc in a cstdlib test, and remove a
couple of !defined(_WIN32)s now that we're explicitly testing
TEST_HAS_ALIGNED_ALLOC rather than TEST_HAS_C11_FEATURES.
Reviewers: danalbert, EricWF, mclow.lists
Reviewed By: danalbert
Subscribers: srhines, christof, libcxx-commits
Tags: #libc
Differential Revision: https://reviews.llvm.org/D69929
2019-11-19 04:16:45 +08:00
|
|
|
# elif defined(__BIONIC__)
|
2020-07-29 01:41:12 +08:00
|
|
|
# if __ANDROID_API__ >= 21
|
|
|
|
# define TEST_HAS_QUICK_EXIT
|
|
|
|
# endif
|
Fix _LIBCPP_HAS_ definitions for Android.
Summary:
Android added quick_exit()/at_quick_exit() in API level 21,
aligned_alloc() in API level 28, and timespec_get() in API level 29,
but has the other C11 features at all API levels (since they're basically
just coming from clang directly).
_LIBCPP_HAS_QUICK_EXIT and _LIBCPP_HAS_TIMESPEC_GET already existed,
so we can reuse them. (And use _LIBCPP_HAS_TIMESPEC_GET in a few more
places where _LIBCPP_HAS_C11_FEATURES has been used as a proxy. This
isn't correct for Android.)
_LIBCPP_HAS_ALIGNED_ALLOC is added, to cover aligned_alloc() (obviously).
Add a missing std:: before aligned_alloc in a cstdlib test, and remove a
couple of !defined(_WIN32)s now that we're explicitly testing
TEST_HAS_ALIGNED_ALLOC rather than TEST_HAS_C11_FEATURES.
Reviewers: danalbert, EricWF, mclow.lists
Reviewed By: danalbert
Subscribers: srhines, christof, libcxx-commits
Tags: #libc
Differential Revision: https://reviews.llvm.org/D69929
2019-11-19 04:16:45 +08:00
|
|
|
# if __ANDROID_API__ >= 28
|
|
|
|
# define TEST_HAS_ALIGNED_ALLOC
|
|
|
|
# endif
|
|
|
|
# if __ANDROID_API__ >= 29
|
|
|
|
# define TEST_HAS_TIMESPEC_GET
|
|
|
|
# endif
|
2019-12-14 21:17:19 +08:00
|
|
|
# elif defined(__Fuchsia__) || defined(__wasi__) || defined(__NetBSD__)
|
2020-07-29 01:41:12 +08:00
|
|
|
# define TEST_HAS_QUICK_EXIT
|
Fix _LIBCPP_HAS_ definitions for Android.
Summary:
Android added quick_exit()/at_quick_exit() in API level 21,
aligned_alloc() in API level 28, and timespec_get() in API level 29,
but has the other C11 features at all API levels (since they're basically
just coming from clang directly).
_LIBCPP_HAS_QUICK_EXIT and _LIBCPP_HAS_TIMESPEC_GET already existed,
so we can reuse them. (And use _LIBCPP_HAS_TIMESPEC_GET in a few more
places where _LIBCPP_HAS_C11_FEATURES has been used as a proxy. This
isn't correct for Android.)
_LIBCPP_HAS_ALIGNED_ALLOC is added, to cover aligned_alloc() (obviously).
Add a missing std:: before aligned_alloc in a cstdlib test, and remove a
couple of !defined(_WIN32)s now that we're explicitly testing
TEST_HAS_ALIGNED_ALLOC rather than TEST_HAS_C11_FEATURES.
Reviewers: danalbert, EricWF, mclow.lists
Reviewed By: danalbert
Subscribers: srhines, christof, libcxx-commits
Tags: #libc
Differential Revision: https://reviews.llvm.org/D69929
2019-11-19 04:16:45 +08:00
|
|
|
# define TEST_HAS_ALIGNED_ALLOC
|
2018-08-16 05:19:08 +08:00
|
|
|
# define TEST_HAS_TIMESPEC_GET
|
2018-08-01 02:23:57 +08:00
|
|
|
# elif defined(__linux__)
|
2018-11-02 06:35:51 +08:00
|
|
|
// This block preserves the old behavior used by include/__config:
|
|
|
|
// _LIBCPP_GLIBC_PREREQ would be defined to 0 if __GLIBC_PREREQ was not
|
|
|
|
// available. The configuration here may be too vague though, as Bionic, uClibc,
|
|
|
|
// newlib, etc may all support these features but need to be configured.
|
|
|
|
# if defined(TEST_GLIBC_PREREQ)
|
2020-07-29 01:41:12 +08:00
|
|
|
# if TEST_GLIBC_PREREQ(2, 15)
|
|
|
|
# define TEST_HAS_QUICK_EXIT
|
|
|
|
# endif
|
2018-11-02 06:35:51 +08:00
|
|
|
# if TEST_GLIBC_PREREQ(2, 17)
|
Fix _LIBCPP_HAS_ definitions for Android.
Summary:
Android added quick_exit()/at_quick_exit() in API level 21,
aligned_alloc() in API level 28, and timespec_get() in API level 29,
but has the other C11 features at all API levels (since they're basically
just coming from clang directly).
_LIBCPP_HAS_QUICK_EXIT and _LIBCPP_HAS_TIMESPEC_GET already existed,
so we can reuse them. (And use _LIBCPP_HAS_TIMESPEC_GET in a few more
places where _LIBCPP_HAS_C11_FEATURES has been used as a proxy. This
isn't correct for Android.)
_LIBCPP_HAS_ALIGNED_ALLOC is added, to cover aligned_alloc() (obviously).
Add a missing std:: before aligned_alloc in a cstdlib test, and remove a
couple of !defined(_WIN32)s now that we're explicitly testing
TEST_HAS_ALIGNED_ALLOC rather than TEST_HAS_C11_FEATURES.
Reviewers: danalbert, EricWF, mclow.lists
Reviewed By: danalbert
Subscribers: srhines, christof, libcxx-commits
Tags: #libc
Differential Revision: https://reviews.llvm.org/D69929
2019-11-19 04:16:45 +08:00
|
|
|
# define TEST_HAS_ALIGNED_ALLOC
|
2018-08-16 05:19:08 +08:00
|
|
|
# define TEST_HAS_TIMESPEC_GET
|
2018-08-01 02:23:57 +08:00
|
|
|
# endif
|
2018-11-02 06:35:51 +08:00
|
|
|
# elif defined(_LIBCPP_HAS_MUSL_LIBC)
|
2020-07-29 01:41:12 +08:00
|
|
|
# define TEST_HAS_QUICK_EXIT
|
Fix _LIBCPP_HAS_ definitions for Android.
Summary:
Android added quick_exit()/at_quick_exit() in API level 21,
aligned_alloc() in API level 28, and timespec_get() in API level 29,
but has the other C11 features at all API levels (since they're basically
just coming from clang directly).
_LIBCPP_HAS_QUICK_EXIT and _LIBCPP_HAS_TIMESPEC_GET already existed,
so we can reuse them. (And use _LIBCPP_HAS_TIMESPEC_GET in a few more
places where _LIBCPP_HAS_C11_FEATURES has been used as a proxy. This
isn't correct for Android.)
_LIBCPP_HAS_ALIGNED_ALLOC is added, to cover aligned_alloc() (obviously).
Add a missing std:: before aligned_alloc in a cstdlib test, and remove a
couple of !defined(_WIN32)s now that we're explicitly testing
TEST_HAS_ALIGNED_ALLOC rather than TEST_HAS_C11_FEATURES.
Reviewers: danalbert, EricWF, mclow.lists
Reviewed By: danalbert
Subscribers: srhines, christof, libcxx-commits
Tags: #libc
Differential Revision: https://reviews.llvm.org/D69929
2019-11-19 04:16:45 +08:00
|
|
|
# define TEST_HAS_ALIGNED_ALLOC
|
2018-08-16 05:19:08 +08:00
|
|
|
# define TEST_HAS_TIMESPEC_GET
|
2018-08-01 02:23:57 +08:00
|
|
|
# endif
|
|
|
|
# elif defined(_WIN32)
|
|
|
|
# if defined(_MSC_VER) && !defined(__MINGW32__)
|
2020-07-29 01:41:12 +08:00
|
|
|
# define TEST_HAS_QUICK_EXIT
|
Fix _LIBCPP_HAS_ definitions for Android.
Summary:
Android added quick_exit()/at_quick_exit() in API level 21,
aligned_alloc() in API level 28, and timespec_get() in API level 29,
but has the other C11 features at all API levels (since they're basically
just coming from clang directly).
_LIBCPP_HAS_QUICK_EXIT and _LIBCPP_HAS_TIMESPEC_GET already existed,
so we can reuse them. (And use _LIBCPP_HAS_TIMESPEC_GET in a few more
places where _LIBCPP_HAS_C11_FEATURES has been used as a proxy. This
isn't correct for Android.)
_LIBCPP_HAS_ALIGNED_ALLOC is added, to cover aligned_alloc() (obviously).
Add a missing std:: before aligned_alloc in a cstdlib test, and remove a
couple of !defined(_WIN32)s now that we're explicitly testing
TEST_HAS_ALIGNED_ALLOC rather than TEST_HAS_C11_FEATURES.
Reviewers: danalbert, EricWF, mclow.lists
Reviewed By: danalbert
Subscribers: srhines, christof, libcxx-commits
Tags: #libc
Differential Revision: https://reviews.llvm.org/D69929
2019-11-19 04:16:45 +08:00
|
|
|
# define TEST_HAS_ALIGNED_ALLOC
|
2018-08-16 05:19:08 +08:00
|
|
|
# define TEST_HAS_TIMESPEC_GET
|
2018-08-01 02:23:57 +08:00
|
|
|
# endif
|
2020-07-28 02:25:03 +08:00
|
|
|
# elif defined(__APPLE__)
|
|
|
|
// timespec_get and aligned_alloc were introduced in macOS 10.15 and
|
|
|
|
// aligned releases
|
2021-04-05 06:05:12 +08:00
|
|
|
# if ((defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101500) || \
|
|
|
|
(defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 130000) || \
|
|
|
|
(defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ >= 130000) || \
|
|
|
|
(defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ >= 60000))
|
2020-07-28 02:25:03 +08:00
|
|
|
# define TEST_HAS_ALIGNED_ALLOC
|
|
|
|
# define TEST_HAS_TIMESPEC_GET
|
|
|
|
# endif
|
|
|
|
# endif // __APPLE__
|
2018-08-01 02:23:57 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Features that were introduced in C++14 */
|
|
|
|
#if TEST_STD_VER >= 14
|
|
|
|
#define TEST_HAS_EXTENDED_CONSTEXPR
|
|
|
|
#define TEST_HAS_VARIABLE_TEMPLATES
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Features that were introduced in C++17 */
|
|
|
|
#if TEST_STD_VER >= 17
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Features that were introduced after C++17 */
|
|
|
|
#if TEST_STD_VER > 17
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2016-10-12 18:19:48 +08:00
|
|
|
#define TEST_ALIGNAS_TYPE(...) TEST_ALIGNAS(TEST_ALIGNOF(__VA_ARGS__))
|
|
|
|
|
2016-06-22 13:40:17 +08:00
|
|
|
#if !TEST_HAS_FEATURE(cxx_rtti) && !defined(__cpp_rtti) \
|
2016-06-22 13:33:52 +08:00
|
|
|
&& !defined(__GXX_RTTI)
|
2015-07-31 10:24:58 +08:00
|
|
|
#define TEST_HAS_NO_RTTI
|
|
|
|
#endif
|
|
|
|
|
2020-07-15 23:26:20 +08:00
|
|
|
#if !defined(TEST_HAS_NO_RTTI)
|
|
|
|
# define RTTI_ASSERT(X) assert(X)
|
|
|
|
#else
|
|
|
|
# define RTTI_ASSERT(X)
|
|
|
|
#endif
|
|
|
|
|
2016-06-22 13:40:17 +08:00
|
|
|
#if !TEST_HAS_FEATURE(cxx_exceptions) && !defined(__cpp_exceptions) \
|
2016-06-22 13:33:52 +08:00
|
|
|
&& !defined(__EXCEPTIONS)
|
2015-07-31 10:24:58 +08:00
|
|
|
#define TEST_HAS_NO_EXCEPTIONS
|
|
|
|
#endif
|
|
|
|
|
2015-10-01 16:34:37 +08:00
|
|
|
#if TEST_HAS_FEATURE(address_sanitizer) || TEST_HAS_FEATURE(memory_sanitizer) || \
|
|
|
|
TEST_HAS_FEATURE(thread_sanitizer)
|
|
|
|
#define TEST_HAS_SANITIZERS
|
|
|
|
#endif
|
|
|
|
|
2016-06-27 03:42:59 +08:00
|
|
|
#if defined(_LIBCPP_NORETURN)
|
|
|
|
#define TEST_NORETURN _LIBCPP_NORETURN
|
|
|
|
#else
|
|
|
|
#define TEST_NORETURN [[noreturn]]
|
|
|
|
#endif
|
|
|
|
|
2018-03-22 14:21:07 +08:00
|
|
|
#if defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION) || \
|
|
|
|
(!(TEST_STD_VER > 14 || \
|
|
|
|
(defined(__cpp_aligned_new) && __cpp_aligned_new >= 201606L)))
|
2018-03-22 12:42:56 +08:00
|
|
|
#define TEST_HAS_NO_ALIGNED_ALLOCATION
|
|
|
|
#endif
|
|
|
|
|
2017-05-25 12:36:24 +08:00
|
|
|
#if defined(_LIBCPP_SAFE_STATIC)
|
|
|
|
#define TEST_SAFE_STATIC _LIBCPP_SAFE_STATIC
|
|
|
|
#else
|
|
|
|
#define TEST_SAFE_STATIC
|
|
|
|
#endif
|
|
|
|
|
2019-10-14 00:46:12 +08:00
|
|
|
#if !defined(__cpp_impl_three_way_comparison) \
|
|
|
|
&& (!defined(_MSC_VER) || defined(__clang__) || _MSC_VER < 1920 || _MSVC_LANG <= 201703L)
|
2018-04-07 05:37:23 +08:00
|
|
|
#define TEST_HAS_NO_SPACESHIP_OPERATOR
|
2019-01-15 09:53:12 +08:00
|
|
|
#endif
|
2018-04-07 05:37:23 +08:00
|
|
|
|
2017-03-23 14:20:18 +08:00
|
|
|
#if TEST_STD_VER < 11
|
|
|
|
#define ASSERT_NOEXCEPT(...)
|
|
|
|
#define ASSERT_NOT_NOEXCEPT(...)
|
|
|
|
#else
|
2016-12-10 03:53:08 +08:00
|
|
|
#define ASSERT_NOEXCEPT(...) \
|
|
|
|
static_assert(noexcept(__VA_ARGS__), "Operation must be noexcept")
|
|
|
|
|
|
|
|
#define ASSERT_NOT_NOEXCEPT(...) \
|
|
|
|
static_assert(!noexcept(__VA_ARGS__), "Operation must NOT be noexcept")
|
2017-03-23 14:20:18 +08:00
|
|
|
#endif
|
2016-12-10 03:53:08 +08:00
|
|
|
|
2016-04-29 06:28:23 +08:00
|
|
|
/* Macros for testing libc++ specific behavior and extensions */
|
|
|
|
#if defined(_LIBCPP_VERSION)
|
|
|
|
#define LIBCPP_ASSERT(...) assert(__VA_ARGS__)
|
|
|
|
#define LIBCPP_STATIC_ASSERT(...) static_assert(__VA_ARGS__)
|
2016-12-10 03:53:08 +08:00
|
|
|
#define LIBCPP_ASSERT_NOEXCEPT(...) ASSERT_NOEXCEPT(__VA_ARGS__)
|
|
|
|
#define LIBCPP_ASSERT_NOT_NOEXCEPT(...) ASSERT_NOT_NOEXCEPT(__VA_ARGS__)
|
2016-10-08 05:27:45 +08:00
|
|
|
#define LIBCPP_ONLY(...) __VA_ARGS__
|
2016-04-29 06:28:23 +08:00
|
|
|
#else
|
|
|
|
#define LIBCPP_ASSERT(...) ((void)0)
|
|
|
|
#define LIBCPP_STATIC_ASSERT(...) ((void)0)
|
2016-12-10 03:53:08 +08:00
|
|
|
#define LIBCPP_ASSERT_NOEXCEPT(...) ((void)0)
|
|
|
|
#define LIBCPP_ASSERT_NOT_NOEXCEPT(...) ((void)0)
|
2016-10-08 05:27:45 +08:00
|
|
|
#define LIBCPP_ONLY(...) ((void)0)
|
2016-04-29 06:28:23 +08:00
|
|
|
#endif
|
|
|
|
|
2021-04-12 03:04:52 +08:00
|
|
|
#if !defined(_LIBCPP_HAS_NO_RANGES)
|
|
|
|
#define TEST_SUPPORTS_RANGES
|
|
|
|
#endif
|
|
|
|
|
2017-11-22 05:37:26 +08:00
|
|
|
#define TEST_IGNORE_NODISCARD (void)
|
|
|
|
|
2016-06-18 03:46:40 +08:00
|
|
|
namespace test_macros_detail {
|
|
|
|
template <class T, class U>
|
|
|
|
struct is_same { enum { value = 0};} ;
|
|
|
|
template <class T>
|
|
|
|
struct is_same<T, T> { enum {value = 1}; };
|
|
|
|
} // namespace test_macros_detail
|
|
|
|
|
|
|
|
#define ASSERT_SAME_TYPE(...) \
|
2017-04-13 06:43:49 +08:00
|
|
|
static_assert((test_macros_detail::is_same<__VA_ARGS__>::value), \
|
2017-05-31 04:12:55 +08:00
|
|
|
"Types differ unexpectedly")
|
2016-06-18 03:46:40 +08:00
|
|
|
|
2016-10-01 18:34:13 +08:00
|
|
|
#ifndef TEST_HAS_NO_EXCEPTIONS
|
|
|
|
#define TEST_THROW(...) throw __VA_ARGS__
|
|
|
|
#else
|
|
|
|
#if defined(__GNUC__)
|
|
|
|
#define TEST_THROW(...) __builtin_abort()
|
|
|
|
#else
|
|
|
|
#include <stdlib.h>
|
|
|
|
#define TEST_THROW(...) ::abort()
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2017-02-08 08:10:10 +08:00
|
|
|
#if defined(__GNUC__) || defined(__clang__)
|
|
|
|
template <class Tp>
|
2018-03-23 05:28:09 +08:00
|
|
|
inline
|
|
|
|
void DoNotOptimize(Tp const& value) {
|
|
|
|
asm volatile("" : : "r,m"(value) : "memory");
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Tp>
|
|
|
|
inline void DoNotOptimize(Tp& value) {
|
|
|
|
#if defined(__clang__)
|
|
|
|
asm volatile("" : "+r,m"(value) : : "memory");
|
|
|
|
#else
|
|
|
|
asm volatile("" : "+m,r"(value) : : "memory");
|
|
|
|
#endif
|
2017-02-08 08:10:10 +08:00
|
|
|
}
|
|
|
|
#else
|
2017-03-11 08:07:08 +08:00
|
|
|
#include <intrin.h>
|
2017-02-08 08:10:10 +08:00
|
|
|
template <class Tp>
|
2017-03-11 08:07:08 +08:00
|
|
|
inline void DoNotOptimize(Tp const& value) {
|
2017-05-04 23:54:09 +08:00
|
|
|
const volatile void* volatile unused = __builtin_addressof(value);
|
|
|
|
static_cast<void>(unused);
|
2017-03-11 08:07:08 +08:00
|
|
|
_ReadWriteBarrier();
|
2017-02-08 08:10:10 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-10-11 02:22:23 +08:00
|
|
|
#if defined(__GNUC__)
|
|
|
|
#define TEST_ALWAYS_INLINE __attribute__((always_inline))
|
|
|
|
#define TEST_NOINLINE __attribute__((noinline))
|
|
|
|
#elif defined(_MSC_VER)
|
|
|
|
#define TEST_ALWAYS_INLINE __forceinline
|
|
|
|
#define TEST_NOINLINE __declspec(noinline)
|
|
|
|
#else
|
|
|
|
#define TEST_ALWAYS_INLINE
|
|
|
|
#define TEST_NOINLINE
|
|
|
|
#endif
|
2018-03-22 12:42:56 +08:00
|
|
|
|
2021-02-26 05:06:18 +08:00
|
|
|
#ifdef _WIN32
|
|
|
|
#define TEST_NOT_WIN32(...) ((void)0)
|
|
|
|
#else
|
|
|
|
#define TEST_NOT_WIN32(...) __VA_ARGS__
|
|
|
|
#endif
|
|
|
|
|
2021-02-26 18:56:41 +08:00
|
|
|
#ifdef _WIN32
|
|
|
|
#define TEST_WIN_NO_FILESYSTEM_PERMS_NONE
|
|
|
|
#endif
|
|
|
|
|
2017-01-14 12:27:58 +08:00
|
|
|
#if defined(__GNUC__)
|
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
#endif
|
|
|
|
|
2015-05-27 08:28:30 +08:00
|
|
|
#endif // SUPPORT_TEST_MACROS_HPP
|