Debian Codegraph @

libcxx/test/libcxx-03/utilities/utility/pairs/pairs.pair/abi.trivially_copyable.compile.pass.cpp

raw
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 //
10 // This test pins down the ABI of std::pair with respect to being "trivially copyable".
11 //
12
13 // This test doesn't work when the deprecated ABI to turn off pair triviality is enabled.
14 // See libcxx/test/libcxx/utilities/utility/pairs/pairs.pair/abi.non_trivial_copy_move.pass.cpp instead.
15 // UNSUPPORTED: libcpp-deprecated-abi-disable-pair-trivial-copy-ctor
16
17 #include <type_traits>
18 #include <utility>
19
20 #include "test_macros.h"
21
22 struct trivially_copyable {
23 int arr[4];
24 };
25
26 struct trivially_copyable_no_copy_assignment {
27 int arr[4];
28 trivially_copyable_no_copy_assignment& operator=(const trivially_copyable_no_copy_assignment&) = delete;
29 };
30 static_assert(std::is_trivially_copyable<trivially_copyable_no_copy_assignment>::value, "");
31
32 struct trivially_copyable_no_move_assignment {
33 int arr[4];
34 trivially_copyable_no_move_assignment& operator=(const trivially_copyable_no_move_assignment&) = delete;
35 };
36 static_assert(std::is_trivially_copyable<trivially_copyable_no_move_assignment>::value, "");
37
38 struct trivially_copyable_no_construction {
39 int arr[4];
40 trivially_copyable_no_construction() = default;
41 trivially_copyable_no_construction(const trivially_copyable_no_construction&) = delete;
42 trivially_copyable_no_construction& operator=(const trivially_copyable_no_construction&) = default;
43 };
44 static_assert(std::is_trivially_copyable<trivially_copyable_no_construction>::value, "");
45
46 static_assert(!std::is_trivially_copyable<std::pair<int&, int> >::value, "");
47 static_assert(!std::is_trivially_copyable<std::pair<int, int&> >::value, "");
48 static_assert(!std::is_trivially_copyable<std::pair<int&, int&> >::value, "");
49
50 static_assert(!std::is_trivially_copyable<std::pair<int, int> >::value, "");
51 static_assert(!std::is_trivially_copyable<std::pair<int, char> >::value, "");
52 static_assert(!std::is_trivially_copyable<std::pair<char, int> >::value, "");
53 static_assert(!std::is_trivially_copyable<std::pair<std::pair<char, char>, int> >::value, "");
54 static_assert(!std::is_trivially_copyable<std::pair<trivially_copyable, int> >::value, "");
55 static_assert(!std::is_trivially_copyable<std::pair<trivially_copyable_no_copy_assignment, int> >::value, "");
56 static_assert(!std::is_trivially_copyable<std::pair<trivially_copyable_no_move_assignment, int> >::value, "");
57 static_assert(!std::is_trivially_copyable<std::pair<trivially_copyable_no_construction, int> >::value, "");
58
59 static_assert(std::is_trivially_copy_constructible<std::pair<int, int> >::value, "");
60 static_assert(std::is_trivially_move_constructible<std::pair<int, int> >::value, "");
61 static_assert(!std::is_trivially_copy_assignable<std::pair<int, int> >::value, "");
62 static_assert(!std::is_trivially_move_assignable<std::pair<int, int> >::value, "");
63 static_assert(std::is_trivially_destructible<std::pair<int, int> >::value, "");