blob: 09d878b143c186e1c933da1966f6ea5e6761d9ea [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
Eric Fiselier76d24462015-12-09 22:03:06 +000029#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 Fiselier8f1d85f2015-05-27 00:28:30 +000035/* 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 Fiselier00f4a492015-08-19 17:21:46 +000071#define TEST_CONSTEXPR constexpr
Eric Fiselier8f1d85f2015-05-27 00:28:30 +000072#define TEST_NOEXCEPT noexcept
Eric Fiselier5ccbc482016-04-22 10:33:56 +000073# if TEST_STD_VER >= 14
74# define TEST_CONSTEXPR_CXX14 constexpr
75# else
76# define TEST_CONSTEXPR_CXX14
77# endif
Eric Fiselier8f1d85f2015-05-27 00:28:30 +000078#else
Eric Fiselier00f4a492015-08-19 17:21:46 +000079#define TEST_CONSTEXPR
Eric Fiselier5ccbc482016-04-22 10:33:56 +000080#define TEST_CONSTEXPR_CXX14
Eric Fiselier8f1d85f2015-05-27 00:28:30 +000081#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
94namespace test_detail {
95
96template <bool> struct static_assert_incomplete_test;
97template <> struct static_assert_incomplete_test<true> {};
98template <unsigned> struct static_assert_check {};
99
100} // end namespace test_detail
101
102
Eric Fiselier7175a072015-07-31 02:24:58 +0000103#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 Fiselierd95ca092015-10-01 08:34:37 +0000111#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 Fiselier8f1d85f2015-05-27 00:28:30 +0000116#endif // SUPPORT_TEST_MACROS_HPP