70 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 <vector>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::int16_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 43#if __SIZE_WIDTH__ == 6444 45static_assert(sizeof(std::vector<bool>) == 24, "");46static_assert(sizeof(std::vector<bool, min_allocator<bool> >) == 24, "");47static_assert(sizeof(std::vector<bool, test_allocator<bool> >) == 40, "");48static_assert(sizeof(std::vector<bool, small_iter_allocator<bool> >) == 6, "");49 50static_assert(TEST_ALIGNOF(std::vector<bool>) == 8, "");51static_assert(TEST_ALIGNOF(std::vector<bool, min_allocator<bool> >) == 8, "");52static_assert(TEST_ALIGNOF(std::vector<bool, test_allocator<bool> >) == 8, "");53static_assert(TEST_ALIGNOF(std::vector<bool, small_iter_allocator<bool> >) == 2, "");54 55#elif __SIZE_WIDTH__ == 3256 57static_assert(sizeof(std::vector<bool>) == 12, "");58static_assert(sizeof(std::vector<bool, min_allocator<bool> >) == 12, "");59static_assert(sizeof(std::vector<bool, test_allocator<bool> >) == 24, "");60static_assert(sizeof(std::vector<bool, small_iter_allocator<bool> >) == 6, "");61 62static_assert(TEST_ALIGNOF(std::vector<bool>) == 4, "");63static_assert(TEST_ALIGNOF(std::vector<bool, min_allocator<bool> >) == 4, "");64static_assert(TEST_ALIGNOF(std::vector<bool, test_allocator<bool> >) == 4, "");65static_assert(TEST_ALIGNOF(std::vector<bool, small_iter_allocator<bool> >) == 2, "");66 67#else68# error std::size_t has an unexpected size69#endif70