brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.2 KiB · 1202879 Raw
88 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++03, c++11, c++1410// <optional>11 12// ~optional();13 14#include <cassert>15#include <optional>16#include <type_traits>17 18#include "test_macros.h"19 20using std::optional;21 22struct PODType {23  int value;24  int value2;25};26 27class X28{29public:30    static bool dtor_called;31    X() = default;32    X(const X&) = default;33    X& operator=(const X&) = default;34    ~X() {dtor_called = true;}35};36 37bool X::dtor_called = false;38 39int main(int, char**)40{41    {42        typedef int T;43        static_assert(std::is_trivially_destructible<T>::value, "");44        static_assert(std::is_trivially_destructible<optional<T>>::value, "");45    }46    {47        typedef double T;48        static_assert(std::is_trivially_destructible<T>::value, "");49        static_assert(std::is_trivially_destructible<optional<T>>::value, "");50    }51    {52        typedef PODType T;53        static_assert(std::is_trivially_destructible<T>::value, "");54        static_assert(std::is_trivially_destructible<optional<T>>::value, "");55    }56    {57        typedef X T;58        static_assert(!std::is_trivially_destructible<T>::value, "");59        static_assert(!std::is_trivially_destructible<optional<T>>::value, "");60        {61            X x;62            optional<X> opt{x};63            assert(X::dtor_called == false);64        }65        assert(X::dtor_called == true);66    }67#if TEST_STD_VER >= 2668    {69      typedef X& T;70      static_assert(std::is_trivially_destructible_v<T>);71      static_assert(std::is_trivially_destructible_v<optional<T>>);72    }73    X::dtor_called = false;74    X x;75    {76      optional<X&> opt{x};77      assert(X::dtor_called == false);78    }79    assert(X::dtor_called == false);80 81    {82      static_assert(std::is_trivially_destructible_v<X (&)()>);83      static_assert(std::is_trivially_destructible_v<optional<X (&)()>>);84    }85#endif86    return 0;87}88