blob: 08ec28f7c7b6c133fd2390a82ce682b5e308de2c [file] [log] [blame]
Eric Fiselier8f1d85f2015-05-27 00:28:30 +00001// -*- 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 Fiselier7175a072015-07-31 02:24:58 +000017#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 Fiselier8f1d85f2015-05-27 00:28:30 +000023#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 Albert1d4a1ed2016-05-25 22:36:09 -070040/* 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 Fiselier8f1d85f2015-05-27 00:28:30 +000048/* 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 Albert1d4a1ed2016-05-25 22:36:09 -070058#if TEST_HAS_EXTENSION(cxx_decltype) || TEST_STD_VER >= 11
59#define TEST_DECLTYPE(T) decltype(T)
Eric Fiselier8f1d85f2015-05-27 00:28:30 +000060#else
Dan Albert1d4a1ed2016-05-25 22:36:09 -070061#define TEST_DECLTYPE(T) __typeof__(T)
62#endif
63
64#if TEST_STD_VER >= 11
65#define TEST_NOEXCEPT noexcept
66#else
Eric Fiselier8f1d85f2015-05-27 00:28:30 +000067#define TEST_NOEXCEPT
68#endif
69
Dan Albert1d4a1ed2016-05-25 22:36:09 -070070#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
80namespace test_detail {
81
82template <bool> struct static_assert_incomplete_test;
83template <> struct static_assert_incomplete_test<true> {};
84template <unsigned> struct static_assert_check {};
85
86} // end namespace test_detail
87
88
Eric Fiselier7175a072015-07-31 02:24:58 +000089#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 Fiselier8f1d85f2015-05-27 00:28:30 +000097#endif // SUPPORT_TEST_MACROS_HPP