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 // UNSUPPORTED: c++03 10 11 // <tuple> 12 13 // template <class... Types> class tuple; 14 15 // ~tuple(); 16 17 // C++17 added: 18 // The destructor of tuple shall be a trivial destructor 19 // if (is_trivially_destructible_v<Types> && ...) is true. 20 21 #include <tuple> 22 #include <string> 23 #include <cassert> 24 #include <type_traits> 25 26 #include "test_macros.h" 27 28 struct TrackDtor { 29 int* count_; 30 constexpr explicit TrackDtor(int* count) : count_(count) {} 31 TEST_CONSTEXPR_CXX14 TrackDtor(TrackDtor&& that) : count_(that.count_) { that.count_ = nullptr; } 32 TEST_CONSTEXPR_CXX20 ~TrackDtor() { if(count_) ++*count_; } 33 }; 34 static_assert(!std::is_trivially_destructible<TrackDtor>::value, ""); 35 36 static_assert(std::is_trivially_destructible<std::tuple<>>::value, ""); 37 static_assert(std::is_trivially_destructible<std::tuple<void*>>::value, ""); 38 static_assert(std::is_trivially_destructible<std::tuple<int, float>>::value, ""); 39 static_assert(!std::is_trivially_destructible<std::tuple<std::string>>::value, ""); 40 static_assert(!std::is_trivially_destructible<std::tuple<int, std::string>>::value, ""); 41 42 TEST_CONSTEXPR_CXX20 bool test() { 43 int count = 0; 44 { 45 std::tuple<TrackDtor> tuple{TrackDtor(&count)}; 46 assert(count == 0); 47 } 48 assert(count == 1); 49 50 return true; 51 } 52 53 int main(int, char**) 54 { 55 test(); 56 #if TEST_STD_VER > 17 57 static_assert(test()); 58 #endif 59 60 return 0; 61 } 62