| 1 |
// Copyright (C) 2018-2025 Free Software Foundation, Inc. |
| 2 |
// |
| 3 |
// This file is part of the GNU ISO C++ Library. This library is free |
| 4 |
// software; you can redistribute it and/or modify it under the |
| 5 |
// terms of the GNU General Public License as published by the |
| 6 |
// Free Software Foundation; either version 3, or (at your option) |
| 7 |
// any later version. |
| 8 |
|
| 9 |
// This library is distributed in the hope that it will be useful, |
| 10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
// GNU General Public License for more details. |
| 13 |
|
| 14 |
// You should have received a copy of the GNU General Public License along |
| 15 |
// with this library; see the file COPYING3. If not see |
| 16 |
// <http://www.gnu.org/licenses/>. |
| 17 |
|
| 18 |
// { dg-do run { target c++17 } } |
| 19 |
// { dg-additional-options "-pthread" { target pthread } } |
| 20 |
// { dg-require-gthreads "" } |
| 21 |
|
| 22 |
#include <memory_resource> |
| 23 |
#include <testsuite_hooks.h> |
| 24 |
#include <testsuite_allocator.h> |
| 25 |
|
| 26 |
void |
| 27 |
test01() |
| 28 |
{ |
| 29 |
__gnu_test::memory_resource test_mr1, test_mr2; |
| 30 |
__gnu_test::default_resource_mgr mgr(&test_mr1); |
| 31 |
|
| 32 |
const std::pmr::pool_options opts{1, 2}; |
| 33 |
using std::pmr::synchronized_pool_resource; |
| 34 |
|
| 35 |
synchronized_pool_resource p1 = {opts, &test_mr2}; |
| 36 |
VERIFY( p1.upstream_resource() == &test_mr2 ); |
| 37 |
synchronized_pool_resource p2; |
| 38 |
VERIFY( p2.upstream_resource() == std::pmr::get_default_resource() ); |
| 39 |
synchronized_pool_resource p3{&test_mr2}; |
| 40 |
VERIFY( p3.upstream_resource() == &test_mr2 ); |
| 41 |
synchronized_pool_resource p4{opts}; |
| 42 |
VERIFY( p4.upstream_resource() == std::pmr::get_default_resource() ); |
| 43 |
|
| 44 |
static_assert(!std::is_copy_constructible_v<synchronized_pool_resource>); |
| 45 |
static_assert(!std::is_copy_assignable_v<synchronized_pool_resource>); |
| 46 |
static_assert(std::is_destructible_v<synchronized_pool_resource>); |
| 47 |
} |
| 48 |
|
| 49 |
void |
| 50 |
test02() |
| 51 |
{ |
| 52 |
__gnu_test::memory_resource test_mr1, test_mr2; |
| 53 |
__gnu_test::default_resource_mgr mgr(&test_mr1); |
| 54 |
|
| 55 |
const std::pmr::pool_options opts{1, 2}; |
| 56 |
|
| 57 |
struct derived : std::pmr::synchronized_pool_resource |
| 58 |
{ |
| 59 |
using synchronized_pool_resource::synchronized_pool_resource; |
| 60 |
}; |
| 61 |
|
| 62 |
derived p1 = {opts, &test_mr2}; |
| 63 |
VERIFY( p1.upstream_resource() == &test_mr2 ); |
| 64 |
derived p2; |
| 65 |
VERIFY( p2.upstream_resource() == std::pmr::get_default_resource() ); |
| 66 |
derived p3{&test_mr2}; |
| 67 |
VERIFY( p3.upstream_resource() == &test_mr2 ); |
| 68 |
derived p4{opts}; |
| 69 |
VERIFY( p4.upstream_resource() == std::pmr::get_default_resource() ); |
| 70 |
|
| 71 |
static_assert(!std::is_copy_constructible_v<derived>); |
| 72 |
static_assert(!std::is_copy_assignable_v<derived>); |
| 73 |
static_assert(std::is_destructible_v<derived>); |
| 74 |
} |
| 75 |
|
| 76 |
int |
| 77 |
main() |
| 78 |
{ |
| 79 |
test01(); |
| 80 |
test02(); |
| 81 |
} |