summaryrefslogtreecommitdiff
path: root/test/support/test_macros.h
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2016-07-23 20:47:26 +0000
committerDimitry Andric <dim@FreeBSD.org>2016-07-23 20:47:26 +0000
commit51072bd6bf79ef2bc6a922079bff57c31c1effbc (patch)
tree91a2effbc9e6f80bdbbf9eb70e06c51ad0867ea0 /test/support/test_macros.h
parentbb5e33f003797b67974a8893f7f2930fc51b8210 (diff)
Notes
Diffstat (limited to 'test/support/test_macros.h')
-rw-r--r--test/support/test_macros.h81
1 files changed, 46 insertions, 35 deletions
diff --git a/test/support/test_macros.h b/test/support/test_macros.h
index c34e8cf7ef14..a072e31b77b7 100644
--- a/test/support/test_macros.h
+++ b/test/support/test_macros.h
@@ -11,6 +11,8 @@
#ifndef SUPPORT_TEST_MACROS_HPP
#define SUPPORT_TEST_MACROS_HPP
+#include <ciso646> // Get STL specific macros like _LIBCPP_VERSION
+
#define TEST_CONCAT1(X, Y) X##Y
#define TEST_CONCAT(X, Y) TEST_CONCAT1(X, Y)
@@ -33,6 +35,7 @@
#endif
/* Make a nice name for the standard version */
+#ifndef TEST_STD_VER
#if __cplusplus <= 199711L
# define TEST_STD_VER 3
#elif __cplusplus <= 201103L
@@ -40,15 +43,8 @@
#elif __cplusplus <= 201402L
# define TEST_STD_VER 14
#else
-# define TEST_STD_VER 99 // greater than current standard
+# define TEST_STD_VER 16 // current year; greater than current standard
#endif
-
-/* Features that were introduced in C++11 */
-#if TEST_STD_VER >= 11
-#define TEST_HAS_RVALUE_REFERENCES
-#define TEST_HAS_VARIADIC_TEMPLATES
-#define TEST_HAS_INITIALIZER_LISTS
-#define TEST_HAS_BASIC_CONSTEXPR
#endif
/* Features that were introduced in C++14 */
@@ -61,44 +57,27 @@
#if TEST_STD_VER > 14
#endif
-#if TEST_HAS_EXTENSION(cxx_decltype) || TEST_STD_VER >= 11
-#define TEST_DECLTYPE(T) decltype(T)
-#else
-#define TEST_DECLTYPE(T) __typeof__(T)
-#endif
-
#if TEST_STD_VER >= 11
#define TEST_CONSTEXPR constexpr
#define TEST_NOEXCEPT noexcept
+# if TEST_STD_VER >= 14
+# define TEST_CONSTEXPR_CXX14 constexpr
+# else
+# define TEST_CONSTEXPR_CXX14
+# endif
#else
#define TEST_CONSTEXPR
+#define TEST_CONSTEXPR_CXX14
#define TEST_NOEXCEPT
#endif
-#if TEST_HAS_EXTENSION(cxx_static_assert) || TEST_STD_VER >= 11
-# define TEST_STATIC_ASSERT(Expr, Msg) static_assert(Expr, Msg)
-#else
-# define TEST_STATIC_ASSERT(Expr, Msg) \
- typedef ::test_detail::static_assert_check<sizeof( \
- ::test_detail::static_assert_incomplete_test<(Expr)>)> \
- TEST_CONCAT(test_assert, __LINE__)
-#
-#endif
-
-namespace test_detail {
-
-template <bool> struct static_assert_incomplete_test;
-template <> struct static_assert_incomplete_test<true> {};
-template <unsigned> struct static_assert_check {};
-
-} // end namespace test_detail
-
-
-#if !TEST_HAS_FEATURE(cxx_rtti) && !defined(__cxx_rtti)
+#if !TEST_HAS_FEATURE(cxx_rtti) && !defined(__cpp_rtti) \
+ && !defined(__GXX_RTTI)
#define TEST_HAS_NO_RTTI
#endif
-#if !TEST_HAS_FEATURE(cxx_exceptions) && !defined(__cxx_exceptions)
+#if !TEST_HAS_FEATURE(cxx_exceptions) && !defined(__cpp_exceptions) \
+ && !defined(__EXCEPTIONS)
#define TEST_HAS_NO_EXCEPTIONS
#endif
@@ -107,4 +86,36 @@ template <unsigned> struct static_assert_check {};
#define TEST_HAS_SANITIZERS
#endif
+#if defined(_LIBCPP_NORETURN)
+#define TEST_NORETURN _LIBCPP_NORETURN
+#else
+#define TEST_NORETURN [[noreturn]]
+#endif
+
+/* Macros for testing libc++ specific behavior and extensions */
+#if defined(_LIBCPP_VERSION)
+#define LIBCPP_ASSERT(...) assert(__VA_ARGS__)
+#define LIBCPP_STATIC_ASSERT(...) static_assert(__VA_ARGS__)
+#else
+#define LIBCPP_ASSERT(...) ((void)0)
+#define LIBCPP_STATIC_ASSERT(...) ((void)0)
+#endif
+
+#define ASSERT_NOEXCEPT(...) \
+ static_assert(noexcept(__VA_ARGS__), "Operation must be noexcept")
+
+#define ASSERT_NOT_NOEXCEPT(...) \
+ static_assert(!noexcept(__VA_ARGS__), "Operation must NOT be noexcept")
+
+namespace test_macros_detail {
+template <class T, class U>
+struct is_same { enum { value = 0};} ;
+template <class T>
+struct is_same<T, T> { enum {value = 1}; };
+} // namespace test_macros_detail
+
+#define ASSERT_SAME_TYPE(...) \
+ static_assert(test_macros_detail::is_same<__VA_ARGS__>::value, \
+ "Types differ uexpectedly")
+
#endif // SUPPORT_TEST_MACROS_HPP