brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.8 KiB · 30586d8 Raw
118 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: libcpp-abi-no-compressed-pair-padding10 11#include <cstdint>12#include <deque>13 14#include "min_allocator.h"15#include "test_allocator.h"16#include "test_macros.h"17 18template <class T>19class small_pointer {20  std::uint16_t offset;21};22 23template <class T>24class small_iter_allocator {25public:26  using value_type      = T;27  using pointer         = small_pointer<T>;28  using size_type       = std::uint16_t;29  using difference_type = std::int16_t;30 31  small_iter_allocator() TEST_NOEXCEPT {}32 33  template <class U>34  small_iter_allocator(small_iter_allocator<U>) TEST_NOEXCEPT {}35 36  T* allocate(std::size_t n);37  void deallocate(T* p, std::size_t);38 39  friend bool operator==(small_iter_allocator, small_iter_allocator) { return true; }40  friend bool operator!=(small_iter_allocator, small_iter_allocator) { return false; }41};42 43template <class T>44class final_small_iter_allocator final {45public:46  using value_type      = T;47  using pointer         = small_pointer<T>;48  using size_type       = std::uint16_t;49  using difference_type = std::int16_t;50 51  final_small_iter_allocator() TEST_NOEXCEPT {}52 53  template <class U>54  final_small_iter_allocator(final_small_iter_allocator<U>) TEST_NOEXCEPT {}55 56  T* allocate(std::size_t n);57  void deallocate(T* p, std::size_t);58 59  friend bool operator==(final_small_iter_allocator, final_small_iter_allocator) { return true; }60  friend bool operator!=(final_small_iter_allocator, final_small_iter_allocator) { return false; }61};62 63#if __SIZE_WIDTH__ == 6464 65static_assert(sizeof(std::deque<int>) == 48, "");66static_assert(sizeof(std::deque<int, min_allocator<int> >) == 48, "");67static_assert(sizeof(std::deque<int, test_allocator<int> >) == 80, "");68static_assert(sizeof(std::deque<int, small_iter_allocator<int> >) == 12, "");69static_assert(sizeof(std::deque<int, final_small_iter_allocator<int> >) == 16, "");70 71static_assert(sizeof(std::deque<char>) == 48, "");72static_assert(sizeof(std::deque<char, min_allocator<char> >) == 48, "");73static_assert(sizeof(std::deque<char, test_allocator<char> >) == 80, "");74static_assert(sizeof(std::deque<char, small_iter_allocator<char> >) == 12, "");75static_assert(sizeof(std::deque<char, final_small_iter_allocator<char> >) == 16, "");76 77static_assert(TEST_ALIGNOF(std::deque<int>) == 8, "");78static_assert(TEST_ALIGNOF(std::deque<int, min_allocator<int> >) == 8, "");79static_assert(TEST_ALIGNOF(std::deque<int, test_allocator<int> >) == 8, "");80static_assert(TEST_ALIGNOF(std::deque<int, small_iter_allocator<int> >) == 2, "");81static_assert(TEST_ALIGNOF(std::deque<int, final_small_iter_allocator<int> >) == 2, "");82 83static_assert(TEST_ALIGNOF(std::deque<char>) == 8, "");84static_assert(TEST_ALIGNOF(std::deque<char, min_allocator<char> >) == 8, "");85static_assert(TEST_ALIGNOF(std::deque<char, test_allocator<char> >) == 8, "");86static_assert(TEST_ALIGNOF(std::deque<char, small_iter_allocator<char> >) == 2, "");87static_assert(TEST_ALIGNOF(std::deque<char, final_small_iter_allocator<char> >) == 2, "");88 89#elif __SIZE_WIDTH__ == 3290 91static_assert(sizeof(std::deque<int>) == 24, "");92static_assert(sizeof(std::deque<int, min_allocator<int> >) == 24, "");93static_assert(sizeof(std::deque<int, test_allocator<int> >) == 48, "");94static_assert(sizeof(std::deque<int, small_iter_allocator<int> >) == 12, "");95static_assert(sizeof(std::deque<int, final_small_iter_allocator<int> >) == 16, "");96 97static_assert(sizeof(std::deque<char>) == 24, "");98static_assert(sizeof(std::deque<char, min_allocator<char> >) == 24, "");99static_assert(sizeof(std::deque<char, test_allocator<char> >) == 48, "");100static_assert(sizeof(std::deque<char, small_iter_allocator<char> >) == 12, "");101static_assert(sizeof(std::deque<char, final_small_iter_allocator<char> >) == 16, "");102 103static_assert(TEST_ALIGNOF(std::deque<int>) == 4, "");104static_assert(TEST_ALIGNOF(std::deque<int, min_allocator<int> >) == 4, "");105static_assert(TEST_ALIGNOF(std::deque<int, test_allocator<int> >) == 4, "");106static_assert(TEST_ALIGNOF(std::deque<int, small_iter_allocator<int> >) == 2, "");107static_assert(TEST_ALIGNOF(std::deque<int, final_small_iter_allocator<int> >) == 2, "");108 109static_assert(TEST_ALIGNOF(std::deque<char>) == 4, "");110static_assert(TEST_ALIGNOF(std::deque<char, min_allocator<char> >) == 4, "");111static_assert(TEST_ALIGNOF(std::deque<char, test_allocator<char> >) == 4, "");112static_assert(TEST_ALIGNOF(std::deque<char, small_iter_allocator<char> >) == 2, "");113static_assert(TEST_ALIGNOF(std::deque<char, final_small_iter_allocator<char> >) == 2, "");114 115#else116#  error std::size_t has an unexpected size117#endif118