1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14
13 // has_unique_object_representations
15 #include <type_traits>
17 #include "test_macros.h"
20 void test_has_unique_object_representations()
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
, "");
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
>, "");
34 void test_has_not_has_unique_object_representations()
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
, "");
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
>, "");
57 struct NonEmptyUnion
{int x
; unsigned y
;};
66 virtual ~Abstract() = 0;
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
>();
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>();
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[]>();