|
6 | 6 | // |
7 | 7 | //===----------------------------------------------------------------------===// |
8 | 8 |
|
9 | | -// UNSUPPORTED: c++03, c++11, c++14 |
| 9 | +// REQUIRES: std-at-least-c++17 |
10 | 10 |
|
11 | 11 | // check that <memory_resource> functions are marked [[nodiscard]] |
12 | 12 |
|
13 | | -// clang-format off |
14 | | - |
15 | 13 | #include <memory_resource> |
16 | 14 |
|
17 | 15 | #include "test_macros.h" |
18 | 16 |
|
19 | 17 | void test() { |
20 | | - std::pmr::memory_resource* resource = std::pmr::null_memory_resource(); |
21 | | - resource->allocate(1); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 18 | + { |
| 19 | + std::pmr::memory_resource* r = std::pmr::null_memory_resource(); |
| 20 | + |
| 21 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 22 | + r->allocate(1); |
| 23 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 24 | + r->is_equal(*r); |
| 25 | + |
| 26 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 27 | + std::pmr::get_default_resource(); |
| 28 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 29 | + std::pmr::new_delete_resource(); |
| 30 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 31 | + std::pmr::null_memory_resource(); |
| 32 | + } |
| 33 | + |
| 34 | + { |
| 35 | + std::pmr::monotonic_buffer_resource r; |
| 36 | + |
| 37 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 38 | + r.upstream_resource(); |
| 39 | + |
| 40 | + struct test_protected : public std::pmr::monotonic_buffer_resource { |
| 41 | + void test() { |
| 42 | + std::pmr::monotonic_buffer_resource other; |
| 43 | + |
| 44 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 45 | + do_allocate(94, 82); |
| 46 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 47 | + is_equal(other); |
| 48 | + } |
| 49 | + }; |
| 50 | + } |
| 51 | + |
| 52 | + { |
| 53 | + std::pmr::polymorphic_allocator<int> a; |
| 54 | + |
| 55 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 56 | + a.allocate(1); |
| 57 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 58 | + a.select_on_container_copy_construction(); |
| 59 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 60 | + a.resource(); |
| 61 | + } |
| 62 | + |
| 63 | + { |
| 64 | + std::pmr::synchronized_pool_resource r; |
| 65 | + |
| 66 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 67 | + r.upstream_resource(); |
| 68 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 69 | + r.options(); |
| 70 | + |
| 71 | + struct test_protected : public std::pmr::synchronized_pool_resource { |
| 72 | + void test() { |
| 73 | + std::pmr::synchronized_pool_resource other; |
| 74 | + |
| 75 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 76 | + do_allocate(94, 82); |
| 77 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 78 | + is_equal(other); |
| 79 | + } |
| 80 | + }; |
| 81 | + } |
| 82 | + |
| 83 | + { |
| 84 | + std::pmr::unsynchronized_pool_resource r; |
| 85 | + |
| 86 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 87 | + r.upstream_resource(); |
| 88 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 89 | + r.options(); |
| 90 | + |
| 91 | + struct test_protected : public std::pmr::unsynchronized_pool_resource { |
| 92 | + void test() { |
| 93 | + std::pmr::unsynchronized_pool_resource other; |
22 | 94 |
|
23 | | - std::pmr::polymorphic_allocator<int> polymorphic_allocator; |
24 | | - polymorphic_allocator.allocate(1); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 95 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 96 | + do_allocate(94, 82); |
| 97 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 98 | + is_equal(other); |
| 99 | + } |
| 100 | + }; |
| 101 | + } |
25 | 102 | } |
0 commit comments