blob: 420f4fac1ceed946919aef813e6c847b6b624ff1 [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
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
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
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
58#if TEST_HAS_EXTENSION(cxx_decltype) || TEST_STD_VER >= 11
59#define TEST_DECLTYPE(T) decltype(T)
60#else
61#define TEST_DECLTYPE(T) __typeof__(T)
62#endif
63
64#if TEST_STD_VER >= 11
Eric Fiselier749adeb2015-08-19 17:21:46 +000065#define TEST_CONSTEXPR constexpr
Eric Fiselier6871bcb2015-05-27 00:28:30 +000066#define TEST_NOEXCEPT noexcept
67#else
Eric Fiselier749adeb2015-08-19 17:21:46 +000068#define TEST_CONSTEXPR
Eric Fiselier6871bcb2015-05-27 00:28:30 +000069#define TEST_NOEXCEPT
70#endif
71
72#if TEST_HAS_EXTENSION(cxx_static_assert) || TEST_STD_VER >= 11
73# define TEST_STATIC_ASSERT(Expr, Msg) static_assert(Expr, Msg)
74#else
75# define TEST_STATIC_ASSERT(Expr, Msg) \
76 typedef ::test_detail::static_assert_check<sizeof( \
77 ::test_detail::static_assert_incomplete_test<(Expr)>)> \
78 TEST_CONCAT(test_assert, __LINE__)
79#
80#endif
81
82namespace test_detail {
83
84template <bool> struct static_assert_incomplete_test;
85template <> struct static_assert_incomplete_test<true> {};
86template <unsigned> struct static_assert_check {};
87
88} // end namespace test_detail
89
90
Eric Fiselier3461dbc2015-07-31 02:24:58 +000091#if !TEST_HAS_FEATURE(cxx_rtti) && !defined(__cxx_rtti)
92#define TEST_HAS_NO_RTTI
93#endif
94
95#if !TEST_HAS_FEATURE(cxx_exceptions) && !defined(__cxx_exceptions)
96#define TEST_HAS_NO_EXCEPTIONS
97#endif
98
Eric Fiselier73629822015-10-01 08:34:37 +000099#if TEST_HAS_FEATURE(address_sanitizer) || TEST_HAS_FEATURE(memory_sanitizer) || \
100 TEST_HAS_FEATURE(thread_sanitizer)
101#define TEST_HAS_SANITIZERS
102#endif
103
Eric Fiselier6871bcb2015-05-27 00:28:30 +0000104#endif // SUPPORT_TEST_MACROS_HPP