diff options
Diffstat (limited to 'test/support/test_macros.h')
-rw-r--r-- | test/support/test_macros.h | 73 |
1 files changed, 66 insertions, 7 deletions
diff --git a/test/support/test_macros.h b/test/support/test_macros.h index a072e31b77b7..40d366ab19dd 100644 --- a/test/support/test_macros.h +++ b/test/support/test_macros.h @@ -22,6 +22,12 @@ #define TEST_HAS_FEATURE(X) 0 #endif +#ifdef __has_include +#define TEST_HAS_INCLUDE(X) __has_include(X) +#else +#define TEST_HAS_INCLUDE(X) 0 +#endif + #ifdef __has_extension #define TEST_HAS_EXTENSION(X) __has_extension(X) #else @@ -33,6 +39,21 @@ #else #define TEST_HAS_BUILTIN(X) 0 #endif +#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 + +#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__) +#endif /* Make a nice name for the standard version */ #ifndef TEST_STD_VER @@ -47,6 +68,13 @@ #endif #endif +// Attempt to deduce GCC version +#if defined(_LIBCPP_VERSION) && TEST_HAS_INCLUDE(<features.h>) +#include <features.h> +#define TEST_HAS_GLIBC +#define TEST_GLIBC_PREREQ(major, minor) __GLIBC_PREREQ(major, minor) +#endif + /* Features that were introduced in C++14 */ #if TEST_STD_VER >= 14 #define TEST_HAS_EXTENDED_CONSTEXPR @@ -58,19 +86,33 @@ #endif #if TEST_STD_VER >= 11 +#define TEST_ALIGNOF(...) alignof(__VA_ARGS__) +#define TEST_ALIGNAS(...) alignas(__VA_ARGS__) #define TEST_CONSTEXPR constexpr #define TEST_NOEXCEPT noexcept +#define TEST_NOEXCEPT_COND(...) noexcept(__VA_ARGS__) # if TEST_STD_VER >= 14 # define TEST_CONSTEXPR_CXX14 constexpr # else # define TEST_CONSTEXPR_CXX14 # endif +# if TEST_STD_VER > 14 +# define TEST_THROW_SPEC(...) +# else +# define TEST_THROW_SPEC(...) throw(__VA_ARGS__) +# endif #else +#define TEST_ALIGNOF(...) __alignof(__VA_ARGS__) +#define TEST_ALIGNAS(...) __attribute__((__aligned__(__VA_ARGS__))) #define TEST_CONSTEXPR #define TEST_CONSTEXPR_CXX14 -#define TEST_NOEXCEPT +#define TEST_NOEXCEPT throw() +#define TEST_NOEXCEPT_COND(...) +#define TEST_THROW_SPEC(...) throw(__VA_ARGS__) #endif +#define TEST_ALIGNAS_TYPE(...) TEST_ALIGNAS(TEST_ALIGNOF(__VA_ARGS__)) + #if !TEST_HAS_FEATURE(cxx_rtti) && !defined(__cpp_rtti) \ && !defined(__GXX_RTTI) #define TEST_HAS_NO_RTTI @@ -92,21 +134,27 @@ #define TEST_NORETURN [[noreturn]] #endif +#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") + /* 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__) +#define LIBCPP_ASSERT_NOEXCEPT(...) ASSERT_NOEXCEPT(__VA_ARGS__) +#define LIBCPP_ASSERT_NOT_NOEXCEPT(...) ASSERT_NOT_NOEXCEPT(__VA_ARGS__) +#define LIBCPP_ONLY(...) __VA_ARGS__ #else #define LIBCPP_ASSERT(...) ((void)0) #define LIBCPP_STATIC_ASSERT(...) ((void)0) +#define LIBCPP_ASSERT_NOEXCEPT(...) ((void)0) +#define LIBCPP_ASSERT_NOT_NOEXCEPT(...) ((void)0) +#define LIBCPP_ONLY(...) ((void)0) #endif -#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") - namespace test_macros_detail { template <class T, class U> struct is_same { enum { value = 0};} ; @@ -118,4 +166,15 @@ struct is_same<T, T> { enum {value = 1}; }; static_assert(test_macros_detail::is_same<__VA_ARGS__>::value, \ "Types differ uexpectedly") +#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 + #endif // SUPPORT_TEST_MACROS_HPP |