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 | |
| 29 | /* Make a nice name for the standard version */ |
| 30 | #if __cplusplus <= 199711L |
| 31 | # define TEST_STD_VER 3 |
| 32 | #elif __cplusplus <= 201103L |
| 33 | # define TEST_STD_VER 11 |
| 34 | #elif __cplusplus <= 201402L |
| 35 | # define TEST_STD_VER 14 |
| 36 | #else |
| 37 | # define TEST_STD_VER 99 // greater than current standard |
| 38 | #endif |
| 39 | |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 40 | /* Features that were introduced in C++11 */ |
| 41 | #if TEST_STD_VER >= 11 |
| 42 | #define TEST_HAS_RVALUE_REFERENCES |
| 43 | #define TEST_HAS_VARIADIC_TEMPLATES |
| 44 | #define TEST_HAS_INITIALIZER_LISTS |
| 45 | #define TEST_HAS_BASIC_CONSTEXPR |
| 46 | #endif |
| 47 | |
Eric Fiselier | 8f1d85f | 2015-05-27 00:28:30 +0000 | [diff] [blame] | 48 | /* Features that were introduced in C++14 */ |
| 49 | #if TEST_STD_VER >= 14 |
| 50 | #define TEST_HAS_EXTENDED_CONSTEXPR |
| 51 | #define TEST_HAS_VARIABLE_TEMPLATES |
| 52 | #endif |
| 53 | |
| 54 | /* Features that were introduced after C++14 */ |
| 55 | #if TEST_STD_VER > 14 |
| 56 | #endif |
| 57 | |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 58 | #if TEST_HAS_EXTENSION(cxx_decltype) || TEST_STD_VER >= 11 |
| 59 | #define TEST_DECLTYPE(T) decltype(T) |
Eric Fiselier | 8f1d85f | 2015-05-27 00:28:30 +0000 | [diff] [blame] | 60 | #else |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 61 | #define TEST_DECLTYPE(T) __typeof__(T) |
| 62 | #endif |
| 63 | |
| 64 | #if TEST_STD_VER >= 11 |
| 65 | #define TEST_NOEXCEPT noexcept |
| 66 | #else |
Eric Fiselier | 8f1d85f | 2015-05-27 00:28:30 +0000 | [diff] [blame] | 67 | #define TEST_NOEXCEPT |
| 68 | #endif |
| 69 | |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 70 | #if TEST_HAS_EXTENSION(cxx_static_assert) || TEST_STD_VER >= 11 |
| 71 | # define TEST_STATIC_ASSERT(Expr, Msg) static_assert(Expr, Msg) |
| 72 | #else |
| 73 | # define TEST_STATIC_ASSERT(Expr, Msg) \ |
| 74 | typedef ::test_detail::static_assert_check<sizeof( \ |
| 75 | ::test_detail::static_assert_incomplete_test<(Expr)>)> \ |
| 76 | TEST_CONCAT(test_assert, __LINE__) |
| 77 | # |
| 78 | #endif |
| 79 | |
| 80 | namespace test_detail { |
| 81 | |
| 82 | template <bool> struct static_assert_incomplete_test; |
| 83 | template <> struct static_assert_incomplete_test<true> {}; |
| 84 | template <unsigned> struct static_assert_check {}; |
| 85 | |
| 86 | } // end namespace test_detail |
| 87 | |
| 88 | |
Eric Fiselier | 7175a07 | 2015-07-31 02:24:58 +0000 | [diff] [blame] | 89 | #if !TEST_HAS_FEATURE(cxx_rtti) && !defined(__cxx_rtti) |
| 90 | #define TEST_HAS_NO_RTTI |
| 91 | #endif |
| 92 | |
| 93 | #if !TEST_HAS_FEATURE(cxx_exceptions) && !defined(__cxx_exceptions) |
| 94 | #define TEST_HAS_NO_EXCEPTIONS |
| 95 | #endif |
| 96 | |
Eric Fiselier | 8f1d85f | 2015-05-27 00:28:30 +0000 | [diff] [blame] | 97 | #endif // SUPPORT_TEST_MACROS_HPP |