blob: a08ca87be935094787f2a8e4cf597f0337ea2adf [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
17#ifdef __has_extension
18#define TEST_HAS_EXTENSION(X) __has_extension(X)
19#else
20#define TEST_HAS_EXTENSION(X) 0
21#endif
22
23/* Make a nice name for the standard version */
24#if __cplusplus <= 199711L
25# define TEST_STD_VER 3
26#elif __cplusplus <= 201103L
27# define TEST_STD_VER 11
28#elif __cplusplus <= 201402L
29# define TEST_STD_VER 14
30#else
31# define TEST_STD_VER 99 // greater than current standard
32#endif
33
34/* Features that were introduced in C++11 */
35#if TEST_STD_VER >= 11
36#define TEST_HAS_RVALUE_REFERENCES
37#define TEST_HAS_VARIADIC_TEMPLATES
38#define TEST_HAS_INITIALIZER_LISTS
39#define TEST_HAS_BASIC_CONSTEXPR
40#endif
41
42/* Features that were introduced in C++14 */
43#if TEST_STD_VER >= 14
44#define TEST_HAS_EXTENDED_CONSTEXPR
45#define TEST_HAS_VARIABLE_TEMPLATES
46#endif
47
48/* Features that were introduced after C++14 */
49#if TEST_STD_VER > 14
50#endif
51
52#if TEST_HAS_EXTENSION(cxx_decltype) || TEST_STD_VER >= 11
53#define TEST_DECLTYPE(T) decltype(T)
54#else
55#define TEST_DECLTYPE(T) __typeof__(T)
56#endif
57
58#if TEST_STD_VER >= 11
59#define TEST_NOEXCEPT noexcept
60#else
61#define TEST_NOEXCEPT
62#endif
63
64#if TEST_HAS_EXTENSION(cxx_static_assert) || TEST_STD_VER >= 11
65# define TEST_STATIC_ASSERT(Expr, Msg) static_assert(Expr, Msg)
66#else
67# define TEST_STATIC_ASSERT(Expr, Msg) \
68 typedef ::test_detail::static_assert_check<sizeof( \
69 ::test_detail::static_assert_incomplete_test<(Expr)>)> \
70 TEST_CONCAT(test_assert, __LINE__)
71#
72#endif
73
74namespace test_detail {
75
76template <bool> struct static_assert_incomplete_test;
77template <> struct static_assert_incomplete_test<true> {};
78template <unsigned> struct static_assert_check {};
79
80} // end namespace test_detail
81
82
83#endif // SUPPORT_TEST_MACROS_HPP