Home | History | Annotate | Download | only in meta.unary.cat
      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_null_pointer
     13 
     14 // UNSUPPORTED: c++98, c++03, c++11
     15 
     16 #include <type_traits>
     17 #include <cstddef>        // for std::nullptr_t
     18 #include "test_macros.h"
     19 
     20 template <class T>
     21 void test_is_null_pointer()
     22 {
     23     static_assert( std::is_null_pointer<T>::value, "");
     24     static_assert( std::is_null_pointer<const T>::value, "");
     25     static_assert( std::is_null_pointer<volatile T>::value, "");
     26     static_assert( std::is_null_pointer<const volatile T>::value, "");
     27 #if TEST_STD_VER > 14
     28     static_assert( std::is_null_pointer_v<T>, "");
     29     static_assert( std::is_null_pointer_v<const T>, "");
     30     static_assert( std::is_null_pointer_v<volatile T>, "");
     31     static_assert( std::is_null_pointer_v<const volatile T>, "");
     32 #endif
     33 }
     34 
     35 template <class T>
     36 void test_is_not_null_pointer()
     37 {
     38     static_assert(!std::is_null_pointer<T>::value, "");
     39     static_assert(!std::is_null_pointer<const T>::value, "");
     40     static_assert(!std::is_null_pointer<volatile T>::value, "");
     41     static_assert(!std::is_null_pointer<const volatile T>::value, "");
     42 #if TEST_STD_VER > 14
     43     static_assert(!std::is_null_pointer_v<T>, "");
     44     static_assert(!std::is_null_pointer_v<const T>, "");
     45     static_assert(!std::is_null_pointer_v<volatile T>, "");
     46     static_assert(!std::is_null_pointer_v<const volatile T>, "");
     47 #endif
     48 }
     49 
     50 class Empty
     51 {
     52 };
     53 
     54 class NotEmpty
     55 {
     56     virtual ~NotEmpty();
     57 };
     58 
     59 union Union {};
     60 
     61 struct bit_zero
     62 {
     63     int :  0;
     64 };
     65 
     66 class Abstract
     67 {
     68     virtual ~Abstract() = 0;
     69 };
     70 
     71 enum Enum {zero, one};
     72 struct incomplete_type;
     73 
     74 typedef void (*FunctionPtr)();
     75 
     76 int main()
     77 {
     78     test_is_null_pointer<std::nullptr_t>();
     79 
     80     test_is_not_null_pointer<void>();
     81     test_is_not_null_pointer<int>();
     82     test_is_not_null_pointer<int&>();
     83     test_is_not_null_pointer<int&&>();
     84     test_is_not_null_pointer<int*>();
     85     test_is_not_null_pointer<double>();
     86     test_is_not_null_pointer<const int*>();
     87     test_is_not_null_pointer<char[3]>();
     88     test_is_not_null_pointer<char[]>();
     89     test_is_not_null_pointer<Union>();
     90     test_is_not_null_pointer<Enum>();
     91     test_is_not_null_pointer<FunctionPtr>();
     92     test_is_not_null_pointer<Empty>();
     93     test_is_not_null_pointer<bit_zero>();
     94     test_is_not_null_pointer<NotEmpty>();
     95     test_is_not_null_pointer<Abstract>();
     96     test_is_not_null_pointer<incomplete_type>();
     97 }
     98