[libcxx] r238267 - Add test macros header to remove dependance on __config macros.

Eric Fiselier eric at efcs.ca
Tue May 26 17:28:31 PDT 2015


Author: ericwf
Date: Tue May 26 19:28:30 2015
New Revision: 238267

URL: http://llvm.org/viewvc/llvm-project?rev=238267&view=rev
Log:
Add test macros header to remove dependance on __config macros.

Added:
    libcxx/trunk/test/libcxx/selftest/test_macros.pass.cpp
    libcxx/trunk/test/support/test_macros.h

Added: libcxx/trunk/test/libcxx/selftest/test_macros.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/selftest/test_macros.pass.cpp?rev=238267&view=auto
==============================================================================
--- libcxx/trunk/test/libcxx/selftest/test_macros.pass.cpp (added)
+++ libcxx/trunk/test/libcxx/selftest/test_macros.pass.cpp Tue May 26 19:28:30 2015
@@ -0,0 +1,58 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Test the "test_macros.h" header.
+#include "test_macros.h"
+
+#ifndef TEST_STD_VER
+#error TEST_STD_VER must be defined
+#endif
+
+#ifndef TEST_DECLTYPE
+#error TEST_DECLTYPE must be defined
+#endif
+
+#ifndef TEST_NOEXCEPT
+#error TEST_NOEXCEPT must be defined
+#endif
+
+#ifndef TEST_STATIC_ASSERT
+#error TEST_STATIC_ASSERT must be defined
+#endif
+
+template <class T, class U>
+struct is_same { enum { value = 0 }; };
+
+template <class T>
+struct is_same<T, T> { enum { value = 1 }; };
+
+int foo() { return 0; }
+
+void test_noexcept() TEST_NOEXCEPT
+{
+}
+
+void test_decltype()
+{
+  typedef TEST_DECLTYPE(foo()) MyType;
+  TEST_STATIC_ASSERT((is_same<MyType, int>::value), "is same");
+}
+
+void test_static_assert()
+{
+    TEST_STATIC_ASSERT((is_same<int, int>::value), "is same");
+    TEST_STATIC_ASSERT((!is_same<int, long>::value), "not same");
+}
+
+int main()
+{
+    test_noexcept();
+    test_decltype();
+    test_static_assert();
+}

Added: libcxx/trunk/test/support/test_macros.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/support/test_macros.h?rev=238267&view=auto
==============================================================================
--- libcxx/trunk/test/support/test_macros.h (added)
+++ libcxx/trunk/test/support/test_macros.h Tue May 26 19:28:30 2015
@@ -0,0 +1,83 @@
+// -*- C++ -*-
+//===---------------------------- test_macros.h ---------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef SUPPORT_TEST_MACROS_HPP
+#define SUPPORT_TEST_MACROS_HPP
+
+#define TEST_CONCAT1(X, Y) X##Y
+#define TEST_CONCAT(X, Y) TEST_CONCAT1(X, Y)
+
+#ifdef __has_extension
+#define TEST_HAS_EXTENSION(X) __has_extension(X)
+#else
+#define TEST_HAS_EXTENSION(X) 0
+#endif
+
+/* Make a nice name for the standard version */
+#if  __cplusplus <= 199711L
+# define TEST_STD_VER 3
+#elif __cplusplus <= 201103L
+# define TEST_STD_VER 11
+#elif __cplusplus <= 201402L
+# define TEST_STD_VER 14
+#else
+# define TEST_STD_VER 99    // 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 */
+#if TEST_STD_VER >= 14
+#define TEST_HAS_EXTENDED_CONSTEXPR
+#define TEST_HAS_VARIABLE_TEMPLATES
+#endif
+
+/* Features that were introduced after C++14 */
+#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_NOEXCEPT noexcept
+#else
+#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
+
+
+#endif // SUPPORT_TEST_MACROS_HPP





More information about the cfe-commits mailing list