brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.8 KiB · 88e3fa7 Raw
74 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: c++03, c++11, c++1410// TODO: Change to XFAIL once https://llvm.org/PR40995 is fixed11// UNSUPPORTED: availability-pmr-missing12 13// <memory_resource>14 15// class synchronized_pool_resource16// class unsynchronized_pool_resource17 18#include <memory_resource>19#include <cassert>20#include <new>21#include <type_traits>22 23#include "count_new.h"24 25class assert_on_compare : public std::pmr::memory_resource {26  void* do_allocate(std::size_t, size_t) override {27    assert(false);28    return nullptr;29  }30 31  void do_deallocate(void*, std::size_t, size_t) override { assert(false); }32 33  bool do_is_equal(const std::pmr::memory_resource&) const noexcept override {34    assert(false);35    return true;36  }37};38 39template <class PoolResource>40void test() {41  // Same type42  {43    PoolResource pr1;44    PoolResource pr2;45    assert(pr1 == pr1);46    assert(pr1 != pr2);47 48    std::pmr::memory_resource& mr1 = pr1;49    std::pmr::memory_resource& mr2 = pr2;50    assert(mr1 == mr1);51    assert(mr1 != mr2);52    assert(mr1 == pr1);53    assert(pr1 == mr1);54    assert(mr1 != pr2);55    assert(pr2 != mr1);56  }57  // Different types58  {59    PoolResource pr1;60    std::pmr::memory_resource& mr1 = pr1;61    assert_on_compare c;62    std::pmr::memory_resource& mr2 = c;63    assert(mr1 != mr2);64    assert(!(mr1 == mr2));65  }66}67 68int main(int, char**) {69  test<std::pmr::synchronized_pool_resource>();70  test<std::pmr::unsynchronized_pool_resource>();71 72  return 0;73}74