| 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 |
// The test suite needs to define the ABI macros on the command line when |
| 10 |
// modules are enabled. |
| 11 |
// UNSUPPORTED: clang-modules-build |
| 12 |
|
| 13 |
// <utility> |
| 14 |
|
| 15 |
// template <class T1, class T2> struct pair |
| 16 |
|
| 17 |
// Test that we provide the non-trivial copy operations when _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR |
| 18 |
// is specified. |
| 19 |
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR |
| 20 |
// ADDITIONAL_COMPILE_FLAGS: -Wno-macro-redefined -Wno-invalid-offsetof |
| 21 |
|
| 22 |
#include <utility> |
| 23 |
#include <type_traits> |
| 24 |
#include <cstdlib> |
| 25 |
#include <cstddef> |
| 26 |
#include <cassert> |
| 27 |
|
| 28 |
#include "test_macros.h" |
| 29 |
|
| 30 |
template <class T> |
| 31 |
struct HasNonTrivialABI : std::integral_constant<bool, |
| 32 |
!std::is_trivially_destructible<T>::value |
| 33 |
|| (std::is_copy_constructible<T>::value && !std::is_trivially_copy_constructible<T>::value) |
| 34 |
> {}; |
| 35 |
|
| 36 |
|
| 37 |
void test_trivial() |
| 38 |
{ |
| 39 |
{ |
| 40 |
typedef std::pair<int, short> P; |
| 41 |
static_assert(std::is_copy_constructible<P>::value, ""); |
| 42 |
static_assert(HasNonTrivialABI<P>::value, ""); |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
void test_layout() { |
| 47 |
typedef std::pair<std::pair<char, char>, char> PairT; |
| 48 |
static_assert(sizeof(PairT) == 3, ""); |
| 49 |
static_assert(TEST_ALIGNOF(PairT) == TEST_ALIGNOF(char), ""); |
| 50 |
static_assert(offsetof(PairT, first) == 0, ""); |
| 51 |
} |
| 52 |
|
| 53 |
int main(int, char**) { |
| 54 |
test_trivial(); |
| 55 |
test_layout(); |
| 56 |
return 0; |
| 57 |
} |