summaryrefslogtreecommitdiff
path: root/test/std/utilities/meta/meta.unary/meta.unary.prop/has_unique_object_representations.pass.cpp
blob: 52100c30404c38b1d28a9ec7362809ebee254409 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//===----------------------------------------------------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: c++98, c++03, c++11, c++14
// UNSUPPORTED: clang-3, clang-4, clang-5, apple-clang, gcc-4, gcc-5, gcc-6

// type_traits

// has_unique_object_representations

#include <type_traits>

#include "test_macros.h"

template <class T>
void test_has_unique_object_representations()
{
    static_assert( std::has_unique_object_representations<T>::value, "");
    static_assert( std::has_unique_object_representations<const T>::value, "");
    static_assert( std::has_unique_object_representations<volatile T>::value, "");
    static_assert( std::has_unique_object_representations<const volatile T>::value, "");

    static_assert( std::has_unique_object_representations_v<T>, "");
    static_assert( std::has_unique_object_representations_v<const T>, "");
    static_assert( std::has_unique_object_representations_v<volatile T>, "");
    static_assert( std::has_unique_object_representations_v<const volatile T>, "");
}

template <class T>
void test_has_not_has_unique_object_representations()
{
    static_assert(!std::has_unique_object_representations<T>::value, "");
    static_assert(!std::has_unique_object_representations<const T>::value, "");
    static_assert(!std::has_unique_object_representations<volatile T>::value, "");
    static_assert(!std::has_unique_object_representations<const volatile T>::value, "");

    static_assert(!std::has_unique_object_representations_v<T>, "");
    static_assert(!std::has_unique_object_representations_v<const T>, "");
    static_assert(!std::has_unique_object_representations_v<volatile T>, "");
    static_assert(!std::has_unique_object_representations_v<const volatile T>, "");
}

class Empty
{
};

class NotEmpty
{
    virtual ~NotEmpty();
};

union EmptyUnion {};
struct NonEmptyUnion {int x; unsigned y;};

struct bit_zero
{
    int :  0;
};

class Abstract
{
    virtual ~Abstract() = 0;
};

struct A
{
    ~A();
    unsigned foo;
};

struct B
{
   char bar;
   int foo;
};


int main()
{
    test_has_not_has_unique_object_representations<void>();
    test_has_not_has_unique_object_representations<Empty>();
    test_has_not_has_unique_object_representations<EmptyUnion>();
    test_has_not_has_unique_object_representations<NotEmpty>();
    test_has_not_has_unique_object_representations<bit_zero>();
    test_has_not_has_unique_object_representations<Abstract>();
    test_has_not_has_unique_object_representations<B>();

//  I would expect all three of these to have unique representations.
//  I would also expect that there are systems where they do not.
//     test_has_not_has_unique_object_representations<int&>();
//     test_has_not_has_unique_object_representations<int *>();
//     test_has_not_has_unique_object_representations<double>();


    test_has_unique_object_representations<unsigned>();
    test_has_unique_object_representations<NonEmptyUnion>();
    test_has_unique_object_representations<char[3]>();
    test_has_unique_object_representations<char[]>();

}