[libcxx] r302158 - [test] variant: enable constexpr construction tests on MSVC STL

Casey Carter via cfe-commits cfe-commits at lists.llvm.org
Thu May 4 08:32:55 PDT 2017


Author: caseycarter
Date: Thu May  4 10:32:54 2017
New Revision: 302158

URL: http://llvm.org/viewvc/llvm-project?rev=302158&view=rev
Log:
[test] variant: enable constexpr construction tests on MSVC STL

* Add a new macro _MSVC_STL_VER to detect when the MSVC STL is being tested
* Workaround C1XX __is_trivially_copyable bug

Added:
    libcxx/trunk/test/support/test.workarounds/c1xx_broken_is_trivially_copyable.pass.cpp
Modified:
    libcxx/trunk/test/std/utilities/variant/variant.variant/variant.ctor/copy.pass.cpp
    libcxx/trunk/test/std/utilities/variant/variant.variant/variant.ctor/move.pass.cpp
    libcxx/trunk/test/support/msvc_stdlib_force_include.hpp
    libcxx/trunk/test/support/test_workarounds.h

Modified: libcxx/trunk/test/std/utilities/variant/variant.variant/variant.ctor/copy.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/variant/variant.variant/variant.ctor/copy.pass.cpp?rev=302158&r1=302157&r2=302158&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/variant/variant.variant/variant.ctor/copy.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/variant/variant.variant/variant.ctor/copy.pass.cpp Thu May  4 10:32:54 2017
@@ -21,6 +21,7 @@
 #include <variant>
 
 #include "test_macros.h"
+#include "test_workarounds.h"
 
 struct NonT {
   NonT(int v) : value(v) {}
@@ -137,14 +138,21 @@ constexpr bool test_constexpr_copy_ctor_
   auto v2 = v;
   return v2.index() == v.index() &&
          v2.index() == Idx &&
-        std::get<Idx>(v2) == std::get<Idx>(v);
+         std::get<Idx>(v2) == std::get<Idx>(v);
 }
 
 void test_constexpr_copy_ctor_extension() {
-#ifdef _LIBCPP_VERSION
+#if defined(_LIBCPP_VER) || defined(_MSVC_STL_VER)
   using V = std::variant<long, void*, const int>;
-  static_assert(std::is_trivially_copyable<V>::value, "");
+#ifdef TEST_WORKAROUND_C1XX_BROKEN_IS_TRIVIALLY_COPYABLE
+  static_assert(std::is_trivially_destructible<V>::value, "");
   static_assert(std::is_trivially_copy_constructible<V>::value, "");
+  static_assert(std::is_trivially_move_constructible<V>::value, "");
+  static_assert(!std::is_copy_assignable<V>::value, "");
+  static_assert(!std::is_move_assignable<V>::value, "");
+#else
+  static_assert(std::is_trivially_copyable<V>::value, "");
+#endif
   static_assert(test_constexpr_copy_ctor_extension_imp<0>(V(42l)), "");
   static_assert(test_constexpr_copy_ctor_extension_imp<1>(V(nullptr)), "");
   static_assert(test_constexpr_copy_ctor_extension_imp<2>(V(101)), "");

Modified: libcxx/trunk/test/std/utilities/variant/variant.variant/variant.ctor/move.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/variant/variant.variant/variant.ctor/move.pass.cpp?rev=302158&r1=302157&r2=302158&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/variant/variant.variant/variant.ctor/move.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/variant/variant.variant/variant.ctor/move.pass.cpp Thu May  4 10:32:54 2017
@@ -22,6 +22,7 @@
 #include <variant>
 
 #include "test_macros.h"
+#include "test_workarounds.h"
 
 struct ThrowsMove {
   ThrowsMove(ThrowsMove &&) noexcept(false) {}
@@ -178,9 +179,17 @@ constexpr bool test_constexpr_ctor_exten
 }
 
 void test_constexpr_move_ctor_extension() {
-#ifdef _LIBCPP_VERSION
+#if defined(_LIBCPP_VER) || defined(_MSVC_STL_VER)
   using V = std::variant<long, void*, const int>;
+#ifdef TEST_WORKAROUND_C1XX_BROKEN_IS_TRIVIALLY_COPYABLE
+  static_assert(std::is_trivially_destructible<V>::value, "");
+  static_assert(std::is_trivially_copy_constructible<V>::value, "");
+  static_assert(std::is_trivially_move_constructible<V>::value, "");
+  static_assert(!std::is_copy_assignable<V>::value, "");
+  static_assert(!std::is_move_assignable<V>::value, "");
+#else
   static_assert(std::is_trivially_copyable<V>::value, "");
+#endif
   static_assert(std::is_trivially_move_constructible<V>::value, "");
   static_assert(test_constexpr_ctor_extension_imp<0>(V(42l)), "");
   static_assert(test_constexpr_ctor_extension_imp<1>(V(nullptr)), "");

Modified: libcxx/trunk/test/support/msvc_stdlib_force_include.hpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/support/msvc_stdlib_force_include.hpp?rev=302158&r1=302157&r2=302158&view=diff
==============================================================================
--- libcxx/trunk/test/support/msvc_stdlib_force_include.hpp (original)
+++ libcxx/trunk/test/support/msvc_stdlib_force_include.hpp Thu May  4 10:32:54 2017
@@ -26,6 +26,11 @@
     #error This header may not be used when targeting libc++
 #endif
 
+// Indicates that we are using the MSVC standard library.
+#ifndef _MSVC_STL_VER
+    #define _MSVC_STL_VER 42
+#endif
+
 struct AssertionDialogAvoider {
     AssertionDialogAvoider() {
         _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);

Added: libcxx/trunk/test/support/test.workarounds/c1xx_broken_is_trivially_copyable.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/support/test.workarounds/c1xx_broken_is_trivially_copyable.pass.cpp?rev=302158&view=auto
==============================================================================
--- libcxx/trunk/test/support/test.workarounds/c1xx_broken_is_trivially_copyable.pass.cpp (added)
+++ libcxx/trunk/test/support/test.workarounds/c1xx_broken_is_trivially_copyable.pass.cpp Thu May  4 10:32:54 2017
@@ -0,0 +1,31 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03
+
+// Verify TEST_WORKAROUND_C1XX_BROKEN_IS_TRIVIALLY_COPYABLE.
+
+#include <type_traits>
+
+#include "test_workarounds.h"
+
+struct S {
+  S(S const&) = default;
+  S(S&&) = default;
+  S& operator=(S const&) = delete;
+  S& operator=(S&&) = delete;
+};
+
+int main() {
+#if defined(TEST_WORKAROUND_C1XX_BROKEN_IS_TRIVIALLY_COPYABLE)
+  static_assert(!std::is_trivially_copyable<S>::value, "");
+#else
+  static_assert(std::is_trivially_copyable<S>::value, "");
+#endif
+}

Modified: libcxx/trunk/test/support/test_workarounds.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/support/test_workarounds.h?rev=302158&r1=302157&r2=302158&view=diff
==============================================================================
--- libcxx/trunk/test/support/test_workarounds.h (original)
+++ libcxx/trunk/test/support/test_workarounds.h Thu May  4 10:32:54 2017
@@ -15,6 +15,7 @@
 
 #if defined(TEST_COMPILER_C1XX)
 # define TEST_WORKAROUND_C1XX_BROKEN_NULLPTR_CONVERSION_OPERATOR
+# define TEST_WORKAROUND_C1XX_BROKEN_IS_TRIVIALLY_COPYABLE
 #endif
 
 #endif // SUPPORT_TEST_WORKAROUNDS_H




More information about the cfe-commits mailing list