Eric Fiselier | 8f1d85f | 2015-05-27 00:28:30 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===---------------------------- test_macros.h ---------------------------===// |
| 3 | // |
| 4 | // The LLVM Compiler Infrastructure |
| 5 | // |
| 6 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | // Source Licenses. See LICENSE.TXT for details. |
| 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | #ifndef SUPPORT_TEST_MACROS_HPP |
| 12 | #define SUPPORT_TEST_MACROS_HPP |
| 13 | |
| 14 | #define TEST_CONCAT1(X, Y) X##Y |
| 15 | #define TEST_CONCAT(X, Y) TEST_CONCAT1(X, Y) |
| 16 | |
Eric Fiselier | 7175a07 | 2015-07-31 02:24:58 +0000 | [diff] [blame] | 17 | #ifdef __has_feature |
| 18 | #define TEST_HAS_FEATURE(X) __has_feature(X) |
| 19 | #else |
| 20 | #define TEST_HAS_FEATURE(X) 0 |
| 21 | #endif |
| 22 | |
Eric Fiselier | 8f1d85f | 2015-05-27 00:28:30 +0000 | [diff] [blame] | 23 | #ifdef __has_extension |
| 24 | #define TEST_HAS_EXTENSION(X) __has_extension(X) |
| 25 | #else |
| 26 | #define TEST_HAS_EXTENSION(X) 0 |
| 27 | #endif |
| 28 | |
Eric Fiselier | 76d2446 | 2015-12-09 22:03:06 +0000 | [diff] [blame] | 29 | #ifdef __has_builtin |
| 30 | #define TEST_HAS_BUILTIN(X) __has_builtin(X) |
| 31 | #else |
| 32 | #define TEST_HAS_BUILTIN(X) 0 |
| 33 | #endif |
| 34 | |
Eric Fiselier | 8f1d85f | 2015-05-27 00:28:30 +0000 | [diff] [blame] | 35 | /* Make a nice name for the standard version */ |
| 36 | #if __cplusplus <= 199711L |
| 37 | # define TEST_STD_VER 3 |
| 38 | #elif __cplusplus <= 201103L |
| 39 | # define TEST_STD_VER 11 |
| 40 | #elif __cplusplus <= 201402L |
| 41 | # define TEST_STD_VER 14 |
| 42 | #else |
| 43 | # define TEST_STD_VER 99 // greater than current standard |
| 44 | #endif |
| 45 | |
| 46 | /* Features that were introduced in C++11 */ |
| 47 | #if TEST_STD_VER >= 11 |
| 48 | #define TEST_HAS_RVALUE_REFERENCES |
| 49 | #define TEST_HAS_VARIADIC_TEMPLATES |
| 50 | #define TEST_HAS_INITIALIZER_LISTS |
| 51 | #define TEST_HAS_BASIC_CONSTEXPR |
| 52 | #endif |
| 53 | |
| 54 | /* Features that were introduced in C++14 */ |
| 55 | #if TEST_STD_VER >= 14 |
| 56 | #define TEST_HAS_EXTENDED_CONSTEXPR |
| 57 | #define TEST_HAS_VARIABLE_TEMPLATES |
| 58 | #endif |
| 59 | |
| 60 | /* Features that were introduced after C++14 */ |
| 61 | #if TEST_STD_VER > 14 |
| 62 | #endif |
| 63 | |
| 64 | #if TEST_HAS_EXTENSION(cxx_decltype) || TEST_STD_VER >= 11 |
| 65 | #define TEST_DECLTYPE(T) decltype(T) |
| 66 | #else |
| 67 | #define TEST_DECLTYPE(T) __typeof__(T) |
| 68 | #endif |
| 69 | |
| 70 | #if TEST_STD_VER >= 11 |
Eric Fiselier | 00f4a49 | 2015-08-19 17:21:46 +0000 | [diff] [blame] | 71 | #define TEST_CONSTEXPR constexpr |
Eric Fiselier | 8f1d85f | 2015-05-27 00:28:30 +0000 | [diff] [blame] | 72 | #define TEST_NOEXCEPT noexcept |
Eric Fiselier | 5ccbc48 | 2016-04-22 10:33:56 +0000 | [diff] [blame^] | 73 | # if TEST_STD_VER >= 14 |
| 74 | # define TEST_CONSTEXPR_CXX14 constexpr |
| 75 | # else |
| 76 | # define TEST_CONSTEXPR_CXX14 |
| 77 | # endif |
Eric Fiselier | 8f1d85f | 2015-05-27 00:28:30 +0000 | [diff] [blame] | 78 | #else |
Eric Fiselier | 00f4a49 | 2015-08-19 17:21:46 +0000 | [diff] [blame] | 79 | #define TEST_CONSTEXPR |
Eric Fiselier | 5ccbc48 | 2016-04-22 10:33:56 +0000 | [diff] [blame^] | 80 | #define TEST_CONSTEXPR_CXX14 |
Eric Fiselier | 8f1d85f | 2015-05-27 00:28:30 +0000 | [diff] [blame] | 81 | #define TEST_NOEXCEPT |
| 82 | #endif |
| 83 | |
| 84 | #if TEST_HAS_EXTENSION(cxx_static_assert) || TEST_STD_VER >= 11 |
| 85 | # define TEST_STATIC_ASSERT(Expr, Msg) static_assert(Expr, Msg) |
| 86 | #else |
| 87 | # define TEST_STATIC_ASSERT(Expr, Msg) \ |
| 88 | typedef ::test_detail::static_assert_check<sizeof( \ |
| 89 | ::test_detail::static_assert_incomplete_test<(Expr)>)> \ |
| 90 | TEST_CONCAT(test_assert, __LINE__) |
| 91 | # |
| 92 | #endif |
| 93 | |
| 94 | namespace test_detail { |
| 95 | |
| 96 | template <bool> struct static_assert_incomplete_test; |
| 97 | template <> struct static_assert_incomplete_test<true> {}; |
| 98 | template <unsigned> struct static_assert_check {}; |
| 99 | |
| 100 | } // end namespace test_detail |
| 101 | |
| 102 | |
Eric Fiselier | 7175a07 | 2015-07-31 02:24:58 +0000 | [diff] [blame] | 103 | #if !TEST_HAS_FEATURE(cxx_rtti) && !defined(__cxx_rtti) |
| 104 | #define TEST_HAS_NO_RTTI |
| 105 | #endif |
| 106 | |
| 107 | #if !TEST_HAS_FEATURE(cxx_exceptions) && !defined(__cxx_exceptions) |
| 108 | #define TEST_HAS_NO_EXCEPTIONS |
| 109 | #endif |
| 110 | |
Eric Fiselier | d95ca09 | 2015-10-01 08:34:37 +0000 | [diff] [blame] | 111 | #if TEST_HAS_FEATURE(address_sanitizer) || TEST_HAS_FEATURE(memory_sanitizer) || \ |
| 112 | TEST_HAS_FEATURE(thread_sanitizer) |
| 113 | #define TEST_HAS_SANITIZERS |
| 114 | #endif |
| 115 | |
Eric Fiselier | 8f1d85f | 2015-05-27 00:28:30 +0000 | [diff] [blame] | 116 | #endif // SUPPORT_TEST_MACROS_HPP |