Debian Codegraph @

libcxx/test/libcxx-03/containers/sequences/list/abi.compile.pass.cpp

raw
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 #include <cstdint>
10 #include <list>
11
12 #include "min_allocator.h"
13 #include "test_allocator.h"
14 #include "test_macros.h"
15
16 template <class T>
17 class small_pointer {
18 std::uint16_t offset;
19 };
20
21 template <class T>
22 class small_iter_allocator {
23 public:
24 using value_type = T;
25 using pointer = small_pointer<T>;
26 using size_type = std::int16_t;
27 using difference_type = std::int16_t;
28
29 small_iter_allocator() TEST_NOEXCEPT {}
30
31 template <class U>
32 small_iter_allocator(small_iter_allocator<U>) TEST_NOEXCEPT {}
33
34 T* allocate(std::size_t n);
35 void deallocate(T* p, std::size_t);
36
37 friend bool operator==(small_iter_allocator, small_iter_allocator) { return true; }
38 friend bool operator!=(small_iter_allocator, small_iter_allocator) { return false; }
39 };
40
41 #if __SIZE_WIDTH__ == 64
42
43 static_assert(sizeof(std::list<int>) == 24, "");
44 static_assert(sizeof(std::list<int, min_allocator<int> >) == 24, "");
45 static_assert(sizeof(std::list<int, test_allocator<int> >) == 40, "");
46 static_assert(sizeof(std::list<int, small_iter_allocator<int> >) == 6, "");
47
48 static_assert(sizeof(std::list<char>) == 24, "");
49 static_assert(sizeof(std::list<char, min_allocator<char> >) == 24, "");
50 static_assert(sizeof(std::list<char, test_allocator<char> >) == 40, "");
51 static_assert(sizeof(std::list<char, small_iter_allocator<char> >) == 6, "");
52
53 static_assert(TEST_ALIGNOF(std::list<int>) == 8, "");
54 static_assert(TEST_ALIGNOF(std::list<int, min_allocator<int> >) == 8, "");
55 static_assert(TEST_ALIGNOF(std::list<int, test_allocator<int> >) == 8, "");
56 static_assert(TEST_ALIGNOF(std::list<int, small_iter_allocator<int> >) == 2, "");
57
58 static_assert(TEST_ALIGNOF(std::list<char>) == 8, "");
59 static_assert(TEST_ALIGNOF(std::list<char, min_allocator<char> >) == 8, "");
60 static_assert(TEST_ALIGNOF(std::list<char, test_allocator<char> >) == 8, "");
61 static_assert(TEST_ALIGNOF(std::list<char, small_iter_allocator<char> >) == 2, "");
62
63 #elif __SIZE_WIDTH__ == 32
64
65 static_assert(sizeof(std::list<int>) == 12, "");
66 static_assert(sizeof(std::list<int, min_allocator<int> >) == 12, "");
67 static_assert(sizeof(std::list<int, test_allocator<int> >) == 24, "");
68 static_assert(sizeof(std::list<int, small_iter_allocator<int> >) == 6, "");
69
70 static_assert(sizeof(std::list<char>) == 12, "");
71 static_assert(sizeof(std::list<char, min_allocator<char> >) == 12, "");
72 static_assert(sizeof(std::list<char, test_allocator<char> >) == 24, "");
73 static_assert(sizeof(std::list<char, small_iter_allocator<char> >) == 6, "");
74
75 static_assert(TEST_ALIGNOF(std::list<int>) == 4, "");
76 static_assert(TEST_ALIGNOF(std::list<int, min_allocator<int> >) == 4, "");
77 static_assert(TEST_ALIGNOF(std::list<int, test_allocator<int> >) == 4, "");
78 static_assert(TEST_ALIGNOF(std::list<int, small_iter_allocator<int> >) == 2, "");
79
80 static_assert(TEST_ALIGNOF(std::list<char>) == 4, "");
81 static_assert(TEST_ALIGNOF(std::list<char, min_allocator<char> >) == 4, "");
82 static_assert(TEST_ALIGNOF(std::list<char, test_allocator<char> >) == 4, "");
83 static_assert(TEST_ALIGNOF(std::list<char, small_iter_allocator<char> >) == 2, "");
84
85 #else
86 # error std::size_t has an unexpected size
87 #endif