Home | History | Annotate | Download | only in meta.unary.prop
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // type_traits
     11 
     12 // is_nothrow_destructible
     13 
     14 #include <type_traits>
     15 
     16 #include "test_macros.h"
     17 
     18 template <class T>
     19 void test_is_nothrow_destructible()
     20 {
     21     static_assert( std::is_nothrow_destructible<T>::value, "");
     22     static_assert( std::is_nothrow_destructible<const T>::value, "");
     23     static_assert( std::is_nothrow_destructible<volatile T>::value, "");
     24     static_assert( std::is_nothrow_destructible<const volatile T>::value, "");
     25 }
     26 
     27 template <class T>
     28 void test_is_not_nothrow_destructible()
     29 {
     30     static_assert(!std::is_nothrow_destructible<T>::value, "");
     31     static_assert(!std::is_nothrow_destructible<const T>::value, "");
     32     static_assert(!std::is_nothrow_destructible<volatile T>::value, "");
     33     static_assert(!std::is_nothrow_destructible<const volatile T>::value, "");
     34 }
     35 
     36 
     37 struct PublicDestructor           { public:     ~PublicDestructor() {}};
     38 struct ProtectedDestructor        { protected:  ~ProtectedDestructor() {}};
     39 struct PrivateDestructor          { private:    ~PrivateDestructor() {}};
     40 
     41 struct VirtualPublicDestructor           { public:    virtual ~VirtualPublicDestructor() {}};
     42 struct VirtualProtectedDestructor        { protected: virtual ~VirtualProtectedDestructor() {}};
     43 struct VirtualPrivateDestructor          { private:   virtual ~VirtualPrivateDestructor() {}};
     44 
     45 struct PurePublicDestructor              { public:    virtual ~PurePublicDestructor() = 0; };
     46 struct PureProtectedDestructor           { protected: virtual ~PureProtectedDestructor() = 0; };
     47 struct PurePrivateDestructor             { private:   virtual ~PurePrivateDestructor() = 0; };
     48 
     49 class Empty
     50 {
     51 };
     52 
     53 
     54 union Union {};
     55 
     56 struct bit_zero
     57 {
     58     int :  0;
     59 };
     60 
     61 class Abstract
     62 {
     63     virtual void foo() = 0;
     64 };
     65 
     66 
     67 int main()
     68 {
     69     test_is_not_nothrow_destructible<void>();
     70     test_is_not_nothrow_destructible<char[]>();
     71     test_is_not_nothrow_destructible<char[][3]>();
     72 
     73     test_is_nothrow_destructible<int&>();
     74     test_is_nothrow_destructible<int>();
     75     test_is_nothrow_destructible<double>();
     76     test_is_nothrow_destructible<int*>();
     77     test_is_nothrow_destructible<const int*>();
     78     test_is_nothrow_destructible<char[3]>();
     79 
     80 #if TEST_STD_VER >= 11
     81     // requires noexcept. These are all destructible.
     82     test_is_nothrow_destructible<PublicDestructor>();
     83     test_is_nothrow_destructible<VirtualPublicDestructor>();
     84     test_is_nothrow_destructible<PurePublicDestructor>();
     85     test_is_nothrow_destructible<bit_zero>();
     86     test_is_nothrow_destructible<Abstract>();
     87     test_is_nothrow_destructible<Empty>();
     88     test_is_nothrow_destructible<Union>();
     89 
     90     // requires access control
     91     test_is_not_nothrow_destructible<ProtectedDestructor>();
     92     test_is_not_nothrow_destructible<PrivateDestructor>();
     93     test_is_not_nothrow_destructible<VirtualProtectedDestructor>();
     94     test_is_not_nothrow_destructible<VirtualPrivateDestructor>();
     95     test_is_not_nothrow_destructible<PureProtectedDestructor>();
     96     test_is_not_nothrow_destructible<PurePrivateDestructor>();
     97 #endif
     98 }
     99