|
6 | 6 | // |
7 | 7 | //===----------------------------------------------------------------------===// |
8 | 8 |
|
9 | | -// UNSUPPORTED: c++03, c++11, c++14, c++17 |
| 9 | +// UNSUPPORTED: c++03 |
10 | 10 |
|
11 | 11 | // check that <functional> functions are marked [[nodiscard]] |
12 | 12 |
|
|
16 | 16 |
|
17 | 17 | void test() { |
18 | 18 | int i = 0; |
19 | | - std::identity()(i); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 19 | + |
| 20 | + // Function wrappers |
| 21 | + |
| 22 | +#if !defined(TEST_HAS_NO_RTTI) |
| 23 | + std::function<void(int)> f; |
| 24 | + const std::function<void(int)> cf; |
| 25 | + |
| 26 | + f.target_type(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 27 | + f.target<void(int)>(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 28 | + cf.target<void(int)>(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 29 | +#endif |
| 30 | + struct ZMT { |
| 31 | + void member_function() {}; |
| 32 | + }; |
| 33 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 34 | + std::mem_fn(&ZMT::member_function); |
| 35 | + |
| 36 | + // Identity |
| 37 | + |
| 38 | + std::identity{}(i); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 39 | + |
| 40 | + // Partial function application |
| 41 | + |
| 42 | +#if TEST_STD_VER >= 23 |
| 43 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 44 | + std::bind_back([](int a) { return a; }, 94); |
| 45 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 46 | + std::bind_front([](int a) { return a; }, 94); |
| 47 | +#endif |
| 48 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 49 | + std::bind([](int a) { return a; }, 94); |
| 50 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 51 | + std::bind<float>([](int a) { return a; }, 94); |
| 52 | + |
| 53 | + // Reference wrappers |
| 54 | + std::reference_wrapper<int> rw{i}; |
| 55 | + rw.get(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 56 | + std::function<int(int)> vf; |
| 57 | + auto rwf = std::ref(vf); |
| 58 | + rwf(1); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 59 | + |
| 60 | + std::ref(i); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 61 | + std::cref(i); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 62 | + |
| 63 | + // Operator function objects |
| 64 | + |
| 65 | + // Arithmetic |
| 66 | + |
| 67 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 68 | + std::plus<int>()(94, 82); |
| 69 | +#if TEST_STD_VER >= 14 |
| 70 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 71 | + std::plus<void>{}(94, 82); |
| 72 | +#endif |
| 73 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 74 | + std::minus<int>()(94, 82); |
| 75 | +#if TEST_STD_VER >= 14 |
| 76 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 77 | + std::minus<void>{}(94, 82); |
| 78 | +#endif |
| 79 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 80 | + std::multiplies<int>()(94, 82); |
| 81 | +#if TEST_STD_VER >= 14 |
| 82 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 83 | + std::multiplies<void>{}(94, 82); |
| 84 | +#endif |
| 85 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 86 | + std::divides<int>()(94, 82); |
| 87 | +#if TEST_STD_VER >= 14 |
| 88 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 89 | + std::divides<void>{}(94, 82); |
| 90 | +#endif |
| 91 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 92 | + std::modulus<int>()(94, 82); |
| 93 | +#if TEST_STD_VER >= 14 |
| 94 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 95 | + std::modulus<void>{}(94, 82); |
| 96 | +#endif |
| 97 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 98 | + std::negate<int>()(94); |
| 99 | +#if TEST_STD_VER >= 14 |
| 100 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 101 | + std::negate<void>{}(94); |
| 102 | +#endif |
| 103 | + |
| 104 | + // Bitwise operations |
| 105 | + |
| 106 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 107 | + std::bit_and<int>()(94, 82); |
| 108 | +#if TEST_STD_VER >= 14 |
| 109 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 110 | + std::bit_and<void>{}(94, 82); |
| 111 | +#endif |
| 112 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 113 | + std::bit_not<int>()(94); |
| 114 | +#if TEST_STD_VER >= 14 |
| 115 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 116 | + std::bit_not<void>{}(94); |
| 117 | +#endif |
| 118 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 119 | + std::bit_or<int>()(94, 82); |
| 120 | +#if TEST_STD_VER >= 14 |
| 121 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 122 | + std::bit_or<void>{}(94, 82); |
| 123 | +#endif |
| 124 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 125 | + std::bit_xor<int>()(94, 82); |
| 126 | +#if TEST_STD_VER >= 14 |
| 127 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 128 | + std::bit_xor<void>{}(94, 82); |
| 129 | +#endif |
| 130 | + |
| 131 | + // Comparisons |
| 132 | + |
| 133 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 134 | + std::equal_to<int>()(94, 82); |
| 135 | +#if TEST_STD_VER >= 14 |
| 136 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 137 | + std::equal_to<void>{}(94, 82); |
| 138 | +#endif |
| 139 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 140 | + std::not_equal_to<int>()(94, 82); |
| 141 | +#if TEST_STD_VER >= 14 |
| 142 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 143 | + std::not_equal_to<void>{}(94, 82); |
| 144 | +#endif |
| 145 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 146 | + std::less<int>()(94, 82); |
| 147 | +#if TEST_STD_VER >= 14 |
| 148 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 149 | + std::less<void>{}(94, 82); |
| 150 | +#endif |
| 151 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 152 | + std::less_equal<int>()(94, 82); |
| 153 | +#if TEST_STD_VER >= 14 |
| 154 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 155 | + std::less_equal<void>{}(94, 82); |
| 156 | +#endif |
| 157 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 158 | + std::greater_equal<int>()(94, 82); |
| 159 | +#if TEST_STD_VER >= 14 |
| 160 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 161 | + std::greater_equal<void>{}(94, 82); |
| 162 | +#endif |
| 163 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 164 | + std::greater<int>()(94, 82); |
| 165 | +#if TEST_STD_VER >= 14 |
| 166 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 167 | + std::greater<void>{}(94, 82); |
| 168 | +#endif |
| 169 | + |
| 170 | + // Logical operations |
| 171 | + |
| 172 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 173 | + std::logical_and<int>()(94, 82); |
| 174 | +#if TEST_STD_VER >= 14 |
| 175 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 176 | + std::logical_and<void>{}(94, 82); |
| 177 | +#endif |
| 178 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 179 | + std::logical_not<int>()(94); |
| 180 | +#if TEST_STD_VER >= 14 |
| 181 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 182 | + std::logical_not<void>{}(94); |
| 183 | +#endif |
| 184 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 185 | + std::logical_or<int>()(94, 82); |
| 186 | +#if TEST_STD_VER >= 14 |
| 187 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 188 | + std::logical_or<void>{}(94, 82); |
| 189 | +#endif |
20 | 190 | } |
0 commit comments