// -*- C++ -*- //===----------------------------------------------------------------------===// // // The LLVM Compiler Infrastructure // // This file is dual licensed under the MIT and the University of Illinois Open // Source Licenses. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // UNSUPPORTED: c++98, c++03, c++11, c++14 // // template class variant; // ~variant(); #include #include #include #include "test_macros.h" struct NonTDtor { static int count; NonTDtor() = default; ~NonTDtor() { ++count; } }; int NonTDtor::count = 0; static_assert(!std::is_trivially_destructible::value, ""); struct NonTDtor1 { static int count; NonTDtor1() = default; ~NonTDtor1() { ++count; } }; int NonTDtor1::count = 0; static_assert(!std::is_trivially_destructible::value, ""); struct TDtor { TDtor(const TDtor &) {} // non-trivial copy ~TDtor() = default; }; static_assert(!std::is_trivially_copy_constructible::value, ""); static_assert(std::is_trivially_destructible::value, ""); int main() { { using V = std::variant; static_assert(std::is_trivially_destructible::value, ""); } { using V = std::variant; static_assert(!std::is_trivially_destructible::value, ""); { V v(std::in_place_index<0>); assert(NonTDtor::count == 0); assert(NonTDtor1::count == 0); } assert(NonTDtor::count == 1); assert(NonTDtor1::count == 0); NonTDtor::count = 0; { V v(std::in_place_index<1>); } assert(NonTDtor::count == 0); assert(NonTDtor1::count == 0); { V v(std::in_place_index<2>); assert(NonTDtor::count == 0); assert(NonTDtor1::count == 0); } assert(NonTDtor::count == 0); assert(NonTDtor1::count == 1); } }