blob: c34e8cf7ef14f6c6cb23d1a1ac36dcf30c23181b [file] [log] [blame]
Eric Fiselier6871bcb2015-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 Fiselier3461dbc2015-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 Fiselier6871bcb2015-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 Fiselierfff5ec02015-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 Fiselier6871bcb2015-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 Fiselier749adeb2015-08-19 17:21:46 +000071#define TEST_CONSTEXPR constexpr
Eric Fiselier6871bcb2015-05-27 00:28:30 +000072#define TEST_NOEXCEPT noexcept
73#else
Eric Fiselier749adeb2015-08-19 17:21:46 +000074#define TEST_CONSTEXPR
Eric Fiselier6871bcb2015-05-27 00:28:30 +000075#define TEST_NOEXCEPT
76#endif
77
78#if TEST_HAS_EXTENSION(cxx_static_assert) || TEST_STD_VER >= 11
79# define TEST_STATIC_ASSERT(Expr, Msg) static_assert(Expr, Msg)
80#else
81# define TEST_STATIC_ASSERT(Expr, Msg) \
82 typedef ::test_detail::static_assert_check<sizeof( \
83 ::test_detail::static_assert_incomplete_test<(Expr)>)> \
84 TEST_CONCAT(test_assert, __LINE__)
85#
86#endif
87
88namespace test_detail {
89
90template <bool> struct static_assert_incomplete_test;
91template <> struct static_assert_incomplete_test<true> {};
92template <unsigned> struct static_assert_check {};
93
94} // end namespace test_detail
95
96
Eric Fiselier3461dbc2015-07-31 02:24:58 +000097#if !TEST_HAS_FEATURE(cxx_rtti) && !defined(__cxx_rtti)
98#define TEST_HAS_NO_RTTI
99#endif
100
101#if !TEST_HAS_FEATURE(cxx_exceptions) && !defined(__cxx_exceptions)
102#define TEST_HAS_NO_EXCEPTIONS
103#endif
104
Eric Fiselier73629822015-10-01 08:34:37 +0000105#if TEST_HAS_FEATURE(address_sanitizer) || TEST_HAS_FEATURE(memory_sanitizer) || \
106 TEST_HAS_FEATURE(thread_sanitizer)
107#define TEST_HAS_SANITIZERS
108#endif
109
Eric Fiselier6871bcb2015-05-27 00:28:30 +0000110#endif // SUPPORT_TEST_MACROS_HPP