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