[libcxx] r275757 - Improve ABI tests for std::pair.
Eric Fiselier via cfe-commits
cfe-commits at lists.llvm.org
Sun Jul 17 21:48:38 PDT 2016
Author: ericwf
Date: Sun Jul 17 23:48:37 2016
New Revision: 275757
URL: http://llvm.org/viewvc/llvm-project?rev=275757&view=rev
Log:
Improve ABI tests for std::pair.
Added:
libcxx/trunk/test/libcxx/utilities/utility/pairs/pairs.pair/non_trivial_copy_move_ABI.pass.cpp
libcxx/trunk/test/libcxx/utilities/utility/pairs/pairs.pair/trivial_copy_move_ABI.pass.cpp
Removed:
libcxx/trunk/test/libcxx/utilities/utility/pairs/pairs.pair/trivial_copy_move.pass.cpp
Added: libcxx/trunk/test/libcxx/utilities/utility/pairs/pairs.pair/non_trivial_copy_move_ABI.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/utilities/utility/pairs/pairs.pair/non_trivial_copy_move_ABI.pass.cpp?rev=275757&view=auto
==============================================================================
--- libcxx/trunk/test/libcxx/utilities/utility/pairs/pairs.pair/non_trivial_copy_move_ABI.pass.cpp (added)
+++ libcxx/trunk/test/libcxx/utilities/utility/pairs/pairs.pair/non_trivial_copy_move_ABI.pass.cpp Sun Jul 17 23:48:37 2016
@@ -0,0 +1,55 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+// <utility>
+
+// template <class T1, class T2> struct pair
+
+// Test that we properly provide the old non-trivial copy operations
+// when the ABI macro is defined.
+
+#define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR
+#include <utility>
+#include <cassert>
+
+#include "test_macros.h"
+
+#if TEST_STD_VER >= 11
+struct Dummy {
+ Dummy(Dummy const&) = delete;
+ Dummy(Dummy &&) = default;
+};
+#endif
+
+int main()
+{
+ typedef std::pair<int, short> P;
+ {
+ static_assert(std::is_copy_constructible<P>::value, "");
+ static_assert(!std::is_trivially_copy_constructible<P>::value, "");
+ static_assert(!std::is_trivially_copyable<P>::value, "");
+ }
+#if TEST_STD_VER >= 11
+ {
+ static_assert(std::is_move_constructible<P>::value, "");
+ static_assert(!std::is_trivially_move_constructible<P>::value, "");
+ static_assert(!std::is_trivially_copyable<P>::value, "");
+ }
+ {
+ using P1 = std::pair<Dummy, int>;
+ // These lines fail because the non-trivial constructors do not provide
+ // SFINAE.
+ // static_assert(!std::is_copy_constructible<P1>::value, "");
+ // static_assert(!std::is_trivially_copy_constructible<P1>::value, "");
+ static_assert(std::is_move_constructible<P1>::value, "");
+ static_assert(!std::is_trivially_move_constructible<P1>::value, "");
+ static_assert(!std::is_trivially_copyable<P>::value, "");
+ }
+#endif
+}
Removed: libcxx/trunk/test/libcxx/utilities/utility/pairs/pairs.pair/trivial_copy_move.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/utilities/utility/pairs/pairs.pair/trivial_copy_move.pass.cpp?rev=275756&view=auto
==============================================================================
--- libcxx/trunk/test/libcxx/utilities/utility/pairs/pairs.pair/trivial_copy_move.pass.cpp (original)
+++ libcxx/trunk/test/libcxx/utilities/utility/pairs/pairs.pair/trivial_copy_move.pass.cpp (removed)
@@ -1,55 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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.
-//
-//===----------------------------------------------------------------------===//
-
-// <utility>
-
-// template <class T1, class T2> struct pair
-
-// Doesn't pass due to use of is_trivially_* trait.
-// XFAIL: gcc-4.9
-
-// Test that we properly provide the old non-trivial copy operations
-// when the ABI macro is defined.
-
-#define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR
-#include <utility>
-#include <cassert>
-
-#include "test_macros.h"
-
-#if TEST_STD_VER >= 11
-struct Dummy {
- Dummy(Dummy const&) = delete;
- Dummy(Dummy &&) = default;
-};
-#endif
-
-int main()
-{
- typedef std::pair<int, short> P;
- {
- static_assert(std::is_copy_constructible<P>::value, "");
- static_assert(!std::is_trivially_copy_constructible<P>::value, "");
- }
-#if TEST_STD_VER >= 11
- {
- static_assert(std::is_move_constructible<P>::value, "");
- static_assert(!std::is_trivially_move_constructible<P>::value, "");
- }
- {
- using P1 = std::pair<Dummy, int>;
- // This line fails because the non-trivial constructors do not provide
- // SFINAE.
- // static_assert(!std::is_copy_constructible<P1>::value, "");
- static_assert(!std::is_trivially_copy_constructible<P1>::value, "");
- static_assert(std::is_move_constructible<P1>::value, "");
- static_assert(!std::is_trivially_move_constructible<P1>::value, "");
- }
-#endif
-}
Added: libcxx/trunk/test/libcxx/utilities/utility/pairs/pairs.pair/trivial_copy_move_ABI.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/utilities/utility/pairs/pairs.pair/trivial_copy_move_ABI.pass.cpp?rev=275757&view=auto
==============================================================================
--- libcxx/trunk/test/libcxx/utilities/utility/pairs/pairs.pair/trivial_copy_move_ABI.pass.cpp (added)
+++ libcxx/trunk/test/libcxx/utilities/utility/pairs/pairs.pair/trivial_copy_move_ABI.pass.cpp Sun Jul 17 23:48:37 2016
@@ -0,0 +1,147 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+// The test fails due to the missing is_trivially_constructible intrinsic.
+// XFAIL: gcc-4.9
+
+// <utility>
+
+// template <class T1, class T2> struct pair
+
+// Test that we properly provide the trivial copy operations by default.
+
+// FreeBSD provides the old ABI. This test checks the new ABI so we need
+// to manually turn it on.
+#if defined(__FreeBSD__)
+#define _LIBCPP_ABI_UNSTABLE
+#endif
+
+#include <utility>
+#include <type_traits>
+#include <cstdlib>
+#include <cassert>
+
+#include "test_macros.h"
+
+#if defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR)
+#error Non-trivial ctor ABI macro defined
+#endif
+
+template <class T>
+struct HasTrivialABI : std::integral_constant<bool,
+ std::is_trivially_destructible<T>::value
+ && (!std::is_copy_constructible<T>::value || std::is_trivially_copy_constructible<T>::value)
+#if TEST_STD_VER >= 11
+ && (!std::is_move_constructible<T>::value || std::is_trivially_move_constructible<T>::value)
+#endif
+> {};
+
+#if TEST_STD_VER >= 11
+struct NonTrivialDtor {
+ NonTrivialDtor(NonTrivialDtor const&) = default;
+ ~NonTrivialDtor();
+};
+NonTrivialDtor::~NonTrivialDtor() {}
+static_assert(!HasTrivialABI<NonTrivialDtor>::value, "");
+
+struct NonTrivialCopy {
+ NonTrivialCopy(NonTrivialCopy const&);
+};
+NonTrivialCopy::NonTrivialCopy(NonTrivialCopy const&) {}
+static_assert(!HasTrivialABI<NonTrivialCopy>::value, "");
+
+struct NonTrivialMove {
+ NonTrivialMove(NonTrivialMove const&) = default;
+ NonTrivialMove(NonTrivialMove&&);
+};
+NonTrivialMove::NonTrivialMove(NonTrivialMove&&) {}
+static_assert(!HasTrivialABI<NonTrivialMove>::value, "");
+
+struct DeletedCopy {
+ DeletedCopy(DeletedCopy const&) = delete;
+ DeletedCopy(DeletedCopy&&) = default;
+};
+static_assert(HasTrivialABI<DeletedCopy>::value, "");
+
+struct TrivialMove {
+ TrivialMove(TrivialMove &&) = default;
+};
+static_assert(HasTrivialABI<TrivialMove>::value, "");
+
+struct Trivial {
+ Trivial(Trivial const&) = default;
+};
+static_assert(HasTrivialABI<Trivial>::value, "");
+#endif
+
+
+int main()
+{
+ {
+ typedef std::pair<int, short> P;
+ static_assert(std::is_copy_constructible<P>::value, "");
+ static_assert(HasTrivialABI<P>::value, "");
+ }
+#if TEST_STD_VER >= 11
+ {
+ typedef std::pair<int, short> P;
+ static_assert(std::is_move_constructible<P>::value, "");
+ static_assert(HasTrivialABI<P>::value, "");
+ }
+ {
+ using P = std::pair<NonTrivialDtor, int>;
+ static_assert(!std::is_trivially_destructible<P>::value, "");
+ static_assert(std::is_copy_constructible<P>::value, "");
+ static_assert(!std::is_trivially_copy_constructible<P>::value, "");
+ static_assert(std::is_move_constructible<P>::value, "");
+ static_assert(!std::is_trivially_move_constructible<P>::value, "");
+ static_assert(!HasTrivialABI<P>::value, "");
+ }
+ {
+ using P = std::pair<NonTrivialCopy, int>;
+ static_assert(std::is_copy_constructible<P>::value, "");
+ static_assert(!std::is_trivially_copy_constructible<P>::value, "");
+ static_assert(std::is_move_constructible<P>::value, "");
+ static_assert(!std::is_trivially_move_constructible<P>::value, "");
+ static_assert(!HasTrivialABI<P>::value, "");
+ }
+ {
+ using P = std::pair<NonTrivialMove, int>;
+ static_assert(std::is_copy_constructible<P>::value, "");
+ static_assert(std::is_trivially_copy_constructible<P>::value, "");
+ static_assert(std::is_move_constructible<P>::value, "");
+ static_assert(!std::is_trivially_move_constructible<P>::value, "");
+ static_assert(!HasTrivialABI<P>::value, "");
+ }
+ {
+ using P = std::pair<DeletedCopy, int>;
+ static_assert(!std::is_copy_constructible<P>::value, "");
+ static_assert(!std::is_trivially_copy_constructible<P>::value, "");
+ static_assert(std::is_move_constructible<P>::value, "");
+ static_assert(std::is_trivially_move_constructible<P>::value, "");
+ static_assert(HasTrivialABI<P>::value, "");
+ }
+ {
+ using P = std::pair<Trivial, int>;
+ static_assert(std::is_copy_constructible<P>::value, "");
+ static_assert(std::is_trivially_copy_constructible<P>::value, "");
+ static_assert(std::is_move_constructible<P>::value, "");
+ static_assert(std::is_trivially_move_constructible<P>::value, "");
+ static_assert(HasTrivialABI<P>::value, "");
+ }
+ {
+ using P = std::pair<TrivialMove, int>;
+ static_assert(!std::is_copy_constructible<P>::value, "");
+ static_assert(!std::is_trivially_copy_constructible<P>::value, "");
+ static_assert(std::is_move_constructible<P>::value, "");
+ static_assert(std::is_trivially_move_constructible<P>::value, "");
+ static_assert(HasTrivialABI<P>::value, "");
+ }
+#endif
+}
More information about the cfe-commits
mailing list