[FMV][GlobalOpt] Enable static resolution of non-FMV callers. (#124314)
[llvm-project.git] / libcxx / test / std / utilities / variant / variant.variant / variant.dtor / dtor.pass.cpp
blob53c5283b2edc6f320020b0bc10dd89423d02d6e2
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 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14
11 // <variant>
13 // template <class ...Types> class variant;
15 // ~variant();
17 #include <cassert>
18 #include <type_traits>
19 #include <variant>
21 #include "test_macros.h"
23 struct NonTDtor {
24 int* count;
25 constexpr NonTDtor(int* a, int*) : count(a) {}
26 TEST_CONSTEXPR_CXX20 ~NonTDtor() { ++*count; }
28 static_assert(!std::is_trivially_destructible<NonTDtor>::value, "");
30 struct NonTDtor1 {
31 int* count;
32 constexpr NonTDtor1(int*, int* b) : count(b) {}
33 TEST_CONSTEXPR_CXX20 ~NonTDtor1() { ++*count; }
35 static_assert(!std::is_trivially_destructible<NonTDtor1>::value, "");
37 struct TDtor {
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, "");
55 int count0 = 0;
56 int count1 = 0;
58 V v(std::in_place_index<0>, &count0, &count1);
59 assert(count0 == 0);
60 assert(count1 == 0);
62 assert(count0 == 1);
63 assert(count1 == 0);
66 int count0 = 0;
67 int count1 = 0;
68 { V v(std::in_place_index<1>); }
69 assert(count0 == 0);
70 assert(count1 == 0);
73 int count0 = 0;
74 int count1 = 0;
76 V v(std::in_place_index<2>, &count0, &count1);
77 assert(count0 == 0);
78 assert(count1 == 0);
80 assert(count0 == 0);
81 assert(count1 == 1);
85 return true;
88 int main(int, char**) {
89 test();
91 #if TEST_STD_VER >= 20
92 static_assert(test());
93 #endif
95 return 0;