has_unique_object_representations.pass.cpp (3303B)
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 // UNSUPPORTED: c++98, c++03, c++11, c++14 11 // UNSUPPORTED: clang-3, clang-4, clang-5, apple-clang, gcc-4, gcc-5, gcc-6 12 13 // type_traits 14 15 // has_unique_object_representations 16 17 #include <type_traits> 18 19 #include "test_macros.h" 20 21 template <class T> 22 void test_has_unique_object_representations() 23 { 24 static_assert( std::has_unique_object_representations<T>::value, ""); 25 static_assert( std::has_unique_object_representations<const T>::value, ""); 26 static_assert( std::has_unique_object_representations<volatile T>::value, ""); 27 static_assert( std::has_unique_object_representations<const volatile T>::value, ""); 28 29 static_assert( std::has_unique_object_representations_v<T>, ""); 30 static_assert( std::has_unique_object_representations_v<const T>, ""); 31 static_assert( std::has_unique_object_representations_v<volatile T>, ""); 32 static_assert( std::has_unique_object_representations_v<const volatile T>, ""); 33 } 34 35 template <class T> 36 void test_has_not_has_unique_object_representations() 37 { 38 static_assert(!std::has_unique_object_representations<T>::value, ""); 39 static_assert(!std::has_unique_object_representations<const T>::value, ""); 40 static_assert(!std::has_unique_object_representations<volatile T>::value, ""); 41 static_assert(!std::has_unique_object_representations<const volatile T>::value, ""); 42 43 static_assert(!std::has_unique_object_representations_v<T>, ""); 44 static_assert(!std::has_unique_object_representations_v<const T>, ""); 45 static_assert(!std::has_unique_object_representations_v<volatile T>, ""); 46 static_assert(!std::has_unique_object_representations_v<const volatile T>, ""); 47 } 48 49 class Empty 50 { 51 }; 52 53 class NotEmpty 54 { 55 virtual ~NotEmpty(); 56 }; 57 58 union EmptyUnion {}; 59 struct NonEmptyUnion {int x; unsigned y;}; 60 61 struct bit_zero 62 { 63 int : 0; 64 }; 65 66 class Abstract 67 { 68 virtual ~Abstract() = 0; 69 }; 70 71 struct A 72 { 73 ~A(); 74 unsigned foo; 75 }; 76 77 struct B 78 { 79 char bar; 80 int foo; 81 }; 82 83 84 int main() 85 { 86 test_has_not_has_unique_object_representations<void>(); 87 test_has_not_has_unique_object_representations<Empty>(); 88 test_has_not_has_unique_object_representations<EmptyUnion>(); 89 test_has_not_has_unique_object_representations<NotEmpty>(); 90 test_has_not_has_unique_object_representations<bit_zero>(); 91 test_has_not_has_unique_object_representations<Abstract>(); 92 test_has_not_has_unique_object_representations<B>(); 93 94 // I would expect all three of these to have unique representations. 95 // I would also expect that there are systems where they do not. 96 // test_has_not_has_unique_object_representations<int&>(); 97 // test_has_not_has_unique_object_representations<int *>(); 98 // test_has_not_has_unique_object_representations<double>(); 99 100 101 test_has_unique_object_representations<unsigned>(); 102 test_has_unique_object_representations<NonEmptyUnion>(); 103 test_has_unique_object_representations<char[3]>(); 104 test_has_unique_object_representations<char[]>(); 105 106 }