brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.4 KiB · a16ae1d Raw
88 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#include <cstdint>10#include <list>11 12#include "min_allocator.h"13#include "test_allocator.h"14#include "test_macros.h"15 16template <class T>17class small_pointer {18  std::uint16_t offset;19};20 21template <class T>22class small_iter_allocator {23public: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__ == 6442 43static_assert(sizeof(std::list<int>) == 24, "");44static_assert(sizeof(std::list<int, min_allocator<int> >) == 24, "");45static_assert(sizeof(std::list<int, test_allocator<int> >) == 40, "");46static_assert(sizeof(std::list<int, small_iter_allocator<int> >) == 6, "");47 48static_assert(sizeof(std::list<char>) == 24, "");49static_assert(sizeof(std::list<char, min_allocator<char> >) == 24, "");50static_assert(sizeof(std::list<char, test_allocator<char> >) == 40, "");51static_assert(sizeof(std::list<char, small_iter_allocator<char> >) == 6, "");52 53static_assert(TEST_ALIGNOF(std::list<int>) == 8, "");54static_assert(TEST_ALIGNOF(std::list<int, min_allocator<int> >) == 8, "");55static_assert(TEST_ALIGNOF(std::list<int, test_allocator<int> >) == 8, "");56static_assert(TEST_ALIGNOF(std::list<int, small_iter_allocator<int> >) == 2, "");57 58static_assert(TEST_ALIGNOF(std::list<char>) == 8, "");59static_assert(TEST_ALIGNOF(std::list<char, min_allocator<char> >) == 8, "");60static_assert(TEST_ALIGNOF(std::list<char, test_allocator<char> >) == 8, "");61static_assert(TEST_ALIGNOF(std::list<char, small_iter_allocator<char> >) == 2, "");62 63#elif __SIZE_WIDTH__ == 3264 65static_assert(sizeof(std::list<int>) == 12, "");66static_assert(sizeof(std::list<int, min_allocator<int> >) == 12, "");67static_assert(sizeof(std::list<int, test_allocator<int> >) == 24, "");68static_assert(sizeof(std::list<int, small_iter_allocator<int> >) == 6, "");69 70static_assert(sizeof(std::list<char>) == 12, "");71static_assert(sizeof(std::list<char, min_allocator<char> >) == 12, "");72static_assert(sizeof(std::list<char, test_allocator<char> >) == 24, "");73static_assert(sizeof(std::list<char, small_iter_allocator<char> >) == 6, "");74 75static_assert(TEST_ALIGNOF(std::list<int>) == 4, "");76static_assert(TEST_ALIGNOF(std::list<int, min_allocator<int> >) == 4, "");77static_assert(TEST_ALIGNOF(std::list<int, test_allocator<int> >) == 4, "");78static_assert(TEST_ALIGNOF(std::list<int, small_iter_allocator<int> >) == 2, "");79 80static_assert(TEST_ALIGNOF(std::list<char>) == 4, "");81static_assert(TEST_ALIGNOF(std::list<char, min_allocator<char> >) == 4, "");82static_assert(TEST_ALIGNOF(std::list<char, test_allocator<char> >) == 4, "");83static_assert(TEST_ALIGNOF(std::list<char, small_iter_allocator<char> >) == 2, "");84 85#else86#  error std::size_t has an unexpected size87#endif88