62 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++0310 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 destructor19// 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 28struct 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};34static_assert(!std::is_trivially_destructible<TrackDtor>::value, "");35 36static_assert(std::is_trivially_destructible<std::tuple<>>::value, "");37static_assert(std::is_trivially_destructible<std::tuple<void*>>::value, "");38static_assert(std::is_trivially_destructible<std::tuple<int, float>>::value, "");39static_assert(!std::is_trivially_destructible<std::tuple<std::string>>::value, "");40static_assert(!std::is_trivially_destructible<std::tuple<int, std::string>>::value, "");41 42TEST_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 53int main(int, char**)54{55 test();56#if TEST_STD_VER > 1757 static_assert(test());58#endif59 60 return 0;61}62