]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/memory_resource/2.cc
1 // { dg-options "-std=gnu++17" }
2 // { dg-do run { target c++17 } }
3 // { dg-skip-if "" { *-*-* } { -fno-aligned-new } }
5 // Copyright (C) 2018-2021 Free Software Foundation, Inc.
7 // This file is part of the GNU ISO C++ Library. This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 3, or (at your option)
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License along
19 // with this library; see the file COPYING3. If not see
20 // <http://www.gnu.org/licenses/>.
22 #include <memory_resource>
23 #include <testsuite_allocator.h>
25 struct R
: std::pmr::memory_resource
{
26 void* do_allocate(std::size_t, std::size_t) override
;
27 void do_deallocate(void*, std::size_t, std::size_t) override
;
28 bool do_is_equal(const std::pmr::memory_resource
&) const noexcept override
;
33 void* R::do_allocate(std::size_t bytes
, std::size_t a
)
36 return ::operator new(bytes
, std::align_val_t(a
));
39 void R::do_deallocate(void* p
, std::size_t bytes
, std::size_t a
)
42 ::operator delete(p
, bytes
, std::align_val_t(a
));
45 bool R::do_is_equal(const std::pmr::memory_resource
& r
) const noexcept
56 auto p
= res
.allocate(1, 1);
59 res
.deallocate(p
, 1, 1);
64 VERIFY( ! (res
!= res
) );
67 struct X
{ int i
= 0; };
68 struct MultipleInheritance
: X
, R
{ };
69 MultipleInheritance m
;
74 VERIFY( m
.is_equal(m
) );
77 VERIFY( ! (m
== res
) );
83 VERIFY( ! (res
== m
) );
94 __gnu_test::memory_resource r1
, r2
;
96 VERIFY( ! (r1
!= r1
) );
97 VERIFY( r1
.is_equal(r1
) );
99 VERIFY( r2
.is_equal(r2
) );
100 VERIFY( ! (r1
== r2
) );
102 VERIFY( ! r1
.is_equal(r2
) );
103 VERIFY( ! (r2
== r1
) );
105 VERIFY( ! r2
.is_equal(r1
) );