1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14
13 // template <class ...Types> class variant;
18 #include <type_traits>
21 #include "test_macros.h"
25 constexpr NonTDtor(int* a
, int*) : count(a
) {}
26 TEST_CONSTEXPR_CXX20
~NonTDtor() { ++*count
; }
28 static_assert(!std::is_trivially_destructible
<NonTDtor
>::value
, "");
32 constexpr NonTDtor1(int*, int* b
) : count(b
) {}
33 TEST_CONSTEXPR_CXX20
~NonTDtor1() { ++*count
; }
35 static_assert(!std::is_trivially_destructible
<NonTDtor1
>::value
, "");
38 constexpr TDtor() = default;
39 constexpr TDtor(const TDtor
&) {} // non-trivial copy
40 TEST_CONSTEXPR_CXX20
~TDtor() = default;
42 static_assert(!std::is_trivially_copy_constructible
<TDtor
>::value
, "");
43 static_assert(std::is_trivially_destructible
<TDtor
>::value
, "");
45 TEST_CONSTEXPR_CXX20
bool test() {
47 using V
= std::variant
<int, long, TDtor
>;
48 static_assert(std::is_trivially_destructible
<V
>::value
, "");
49 [[maybe_unused
]] V
v(std::in_place_index
<2>);
52 using V
= std::variant
<NonTDtor
, int, NonTDtor1
>;
53 static_assert(!std::is_trivially_destructible
<V
>::value
, "");
58 V
v(std::in_place_index
<0>, &count0
, &count1
);
68 { V
v(std::in_place_index
<1>); }
76 V
v(std::in_place_index
<2>, &count0
, &count1
);
88 int main(int, char**) {
91 #if TEST_STD_VER >= 20
92 static_assert(test());