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

source code of libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/has_unique_object_representations.pass.cpp