2015-05-27 08:28:30 +08:00
|
|
|
// -*- C++ -*-
|
|
|
|
//===---------------------------- test_macros.h ---------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
|
|
|
// Source Licenses. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef SUPPORT_TEST_MACROS_HPP
|
|
|
|
#define SUPPORT_TEST_MACROS_HPP
|
|
|
|
|
2016-04-29 06:28:23 +08:00
|
|
|
#include <ciso646> // Get STL specific macros like _LIBCPP_VERSION
|
|
|
|
|
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
|
|
|
|
|
2016-10-05 05:25:51 +08:00
|
|
|
#ifdef __has_include
|
|
|
|
#define TEST_HAS_INCLUDE(X) __has_include(X)
|
|
|
|
#else
|
|
|
|
#define TEST_HAS_INCLUDE(X) 0
|
|
|
|
#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
|
|
|
|
|
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
|
|
|
|
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__)
|
|
|
|
#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
|
|
|
|
#else
|
2016-06-27 09:02:43 +08:00
|
|
|
# define TEST_STD_VER 16 // current year; greater than current standard
|
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
|
|
|
|
2016-09-04 08:48:54 +08:00
|
|
|
// Attempt to deduce GCC version
|
2016-10-05 05:25:51 +08:00
|
|
|
#if defined(_LIBCPP_VERSION) && TEST_HAS_INCLUDE(<features.h>)
|
2016-09-04 08:48:54 +08:00
|
|
|
#include <features.h>
|
|
|
|
#define TEST_HAS_GLIBC
|
|
|
|
#define TEST_GLIBC_PREREQ(major, minor) __GLIBC_PREREQ(major, minor)
|
|
|
|
#endif
|
|
|
|
|
2015-05-27 08:28:30 +08:00
|
|
|
/* 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 after C++14 */
|
|
|
|
#if TEST_STD_VER > 14
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if TEST_STD_VER >= 11
|
2015-08-20 01:21:46 +08:00
|
|
|
#define TEST_CONSTEXPR constexpr
|
2015-05-27 08:28:30 +08:00
|
|
|
#define TEST_NOEXCEPT noexcept
|
2016-10-12 17:31:26 +08:00
|
|
|
#define TEST_NOEXCEPT_COND(...) noexcept(__VA_ARGS__)
|
2016-04-22 18:33:56 +08:00
|
|
|
# if TEST_STD_VER >= 14
|
|
|
|
# define TEST_CONSTEXPR_CXX14 constexpr
|
|
|
|
# else
|
|
|
|
# define TEST_CONSTEXPR_CXX14
|
|
|
|
# endif
|
2016-10-12 18:19:48 +08:00
|
|
|
#define TEST_ALIGNOF(...) alignof(__VA_ARGS__)
|
|
|
|
#define TEST_ALIGNAS(...) alignas(__VA_ARGS__)
|
2015-05-27 08:28:30 +08:00
|
|
|
#else
|
2015-08-20 01:21:46 +08:00
|
|
|
#define TEST_CONSTEXPR
|
2016-04-22 18:33:56 +08:00
|
|
|
#define TEST_CONSTEXPR_CXX14
|
2016-10-12 19:20:27 +08:00
|
|
|
#define TEST_NOEXCEPT throw()
|
2016-10-12 17:31:26 +08:00
|
|
|
#define TEST_NOEXCEPT_COND(...)
|
2016-10-12 18:19:48 +08:00
|
|
|
#define TEST_ALIGNOF(...) __alignof(__VA_ARGS__)
|
|
|
|
#define TEST_ALIGNAS(...) __attribute__((__aligned__(__VA_ARGS__)))
|
2015-05-27 08:28:30 +08:00
|
|
|
#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
|
|
|
|
|
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
|
|
|
|
|
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-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-10-08 05:27:45 +08:00
|
|
|
#define LIBCPP_ONLY(...) ((void)0)
|
2016-04-29 06:28:23 +08:00
|
|
|
#endif
|
|
|
|
|
2016-06-18 03:46:40 +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")
|
|
|
|
|
|
|
|
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(...) \
|
|
|
|
static_assert(test_macros_detail::is_same<__VA_ARGS__>::value, \
|
|
|
|
"Types differ uexpectedly")
|
|
|
|
|
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
|
|
|
|
|
2015-05-27 08:28:30 +08:00
|
|
|
#endif // SUPPORT_TEST_MACROS_HPP
|