brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · d79a893 Raw
64 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 monotonic_buffer_resource16 17#include <memory_resource>18#include <cassert>19#include <cstddef> // size_t20 21struct assert_on_compare : public std::pmr::memory_resource {22  void* do_allocate(std::size_t, size_t) override {23    assert(false);24    return nullptr;25  }26 27  void do_deallocate(void*, std::size_t, size_t) override { assert(false); }28 29  bool do_is_equal(const std::pmr::memory_resource&) const noexcept override {30    assert(false);31    return true;32  }33};34 35int main(int, char**) {36  // Same object37  {38    std::pmr::monotonic_buffer_resource r1;39    std::pmr::monotonic_buffer_resource r2;40    assert(r1 == r1);41    assert(r1 != r2);42 43    std::pmr::memory_resource& p1 = r1;44    std::pmr::memory_resource& p2 = r2;45    assert(p1 == p1);46    assert(p1 != p2);47    assert(p1 == r1);48    assert(r1 == p1);49    assert(p1 != r2);50    assert(r2 != p1);51  }52  // Different types53  {54    std::pmr::monotonic_buffer_resource mono1;55    std::pmr::memory_resource& r1 = mono1;56    assert_on_compare c;57    std::pmr::memory_resource& r2 = c;58    assert(r1 != r2);59    assert(!(r1 == r2));60  }61 62  return 0;63}64