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"
26 ~NonTDtor() { ++count
; }
28 int NonTDtor::count
= 0;
29 static_assert(!std::is_trivially_destructible
<NonTDtor
>::value
, "");
33 NonTDtor1() = default;
34 ~NonTDtor1() { ++count
; }
36 int NonTDtor1::count
= 0;
37 static_assert(!std::is_trivially_destructible
<NonTDtor1
>::value
, "");
40 TDtor(const TDtor
&) {} // non-trivial copy
43 static_assert(!std::is_trivially_copy_constructible
<TDtor
>::value
, "");
44 static_assert(std::is_trivially_destructible
<TDtor
>::value
, "");
46 int main(int, char**) {
48 using V
= std::variant
<int, long, TDtor
>;
49 static_assert(std::is_trivially_destructible
<V
>::value
, "");
52 using V
= std::variant
<NonTDtor
, int, NonTDtor1
>;
53 static_assert(!std::is_trivially_destructible
<V
>::value
, "");
55 V
v(std::in_place_index
<0>);
56 assert(NonTDtor::count
== 0);
57 assert(NonTDtor1::count
== 0);
59 assert(NonTDtor::count
== 1);
60 assert(NonTDtor1::count
== 0);
62 { V
v(std::in_place_index
<1>); }
63 assert(NonTDtor::count
== 0);
64 assert(NonTDtor1::count
== 0);
66 V
v(std::in_place_index
<2>);
67 assert(NonTDtor::count
== 0);
68 assert(NonTDtor1::count
== 0);
70 assert(NonTDtor::count
== 0);
71 assert(NonTDtor1::count
== 1);