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