|
| 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 | +#include <type_traits> |
| 14 | +#include <utility> |
| 15 | + |
| 16 | +#include "test_macros.h" |
| 17 | + |
| 18 | +struct trivially_copyable { |
| 19 | + int arr[4]; |
| 20 | +}; |
| 21 | + |
| 22 | +struct trivially_copyable_no_assignment { |
| 23 | + int arr[4]; |
| 24 | + trivially_copyable_no_assignment& operator=(const trivially_copyable_no_assignment&) = delete; |
| 25 | +}; |
| 26 | +static_assert(std::is_trivially_copyable<trivially_copyable_no_assignment>::value, ""); |
| 27 | + |
| 28 | +struct trivially_copyable_no_construction { |
| 29 | + int arr[4]; |
| 30 | + trivially_copyable_no_construction() = default; |
| 31 | + trivially_copyable_no_construction(const trivially_copyable_no_construction&) = delete; |
| 32 | + trivially_copyable_no_construction& operator=(const trivially_copyable_no_construction&) = default; |
| 33 | +}; |
| 34 | +static_assert(std::is_trivially_copyable<trivially_copyable_no_construction>::value, ""); |
| 35 | + |
| 36 | +static_assert((!std::is_trivially_copyable<std::pair<int&, int> >::value), ""); |
| 37 | +static_assert((!std::is_trivially_copyable<std::pair<int, int&> >::value), ""); |
| 38 | +static_assert((!std::is_trivially_copyable<std::pair<int&, int&> >::value), ""); |
| 39 | + |
| 40 | +static_assert((!std::is_trivially_copyable<std::pair<int, int> >::value), ""); |
| 41 | +static_assert((!std::is_trivially_copyable<std::pair<int, char> >::value), ""); |
| 42 | +static_assert((!std::is_trivially_copyable<std::pair<char, int> >::value), ""); |
| 43 | +static_assert((!std::is_trivially_copyable<std::pair<std::pair<char, char>, int> >::value), ""); |
| 44 | +static_assert((!std::is_trivially_copyable<std::pair<trivially_copyable, int> >::value), ""); |
| 45 | +#if TEST_STD_VER == 03 // Known ABI difference |
| 46 | +static_assert((!std::is_trivially_copyable<std::pair<trivially_copyable_no_assignment, int> >::value), ""); |
| 47 | +#else |
| 48 | +static_assert((std::is_trivially_copyable<std::pair<trivially_copyable_no_assignment, int> >::value), ""); |
| 49 | +#endif |
| 50 | +static_assert((!std::is_trivially_copyable<std::pair<trivially_copyable_no_construction, int> >::value), ""); |
| 51 | + |
| 52 | +static_assert((std::is_trivially_copy_constructible<std::pair<int, int> >::value), ""); |
| 53 | +static_assert((std::is_trivially_move_constructible<std::pair<int, int> >::value), ""); |
| 54 | +static_assert((!std::is_trivially_copy_assignable<std::pair<int, int> >::value), ""); |
| 55 | +static_assert((!std::is_trivially_move_assignable<std::pair<int, int> >::value), ""); |
| 56 | +static_assert((std::is_trivially_destructible<std::pair<int, int> >::value), ""); |
0 commit comments