|
15 | 15 |
|
16 | 16 | #include <test_macros.h> |
17 | 17 |
|
18 | | -template <std::size_t N> |
| 18 | +template <typename ArrT> |
19 | 19 | void test_members() { |
20 | | - std::array<int, N> a; |
21 | | - const std::array<int, N> ca{}; |
| 20 | + ArrT a{}; |
22 | 21 |
|
23 | | - a.begin(); // expected-warning 2 {{ignoring return value of function declared with 'nodiscard' attribute}} |
24 | | - ca.begin(); // expected-warning 2 {{ignoring return value of function declared with 'nodiscard' attribute}} |
25 | | - a.end(); // expected-warning 2 {{ignoring return value of function declared with 'nodiscard' attribute}} |
26 | | - ca.end(); // expected-warning 2 {{ignoring return value of function declared with 'nodiscard' attribute}} |
27 | | - a.rbegin(); // expected-warning 2 {{ignoring return value of function declared with 'nodiscard' attribute}} |
28 | | - ca.rbegin(); // expected-warning 2 {{ignoring return value of function declared with 'nodiscard' attribute}} |
29 | | - a.rend(); // expected-warning 2 {{ignoring return value of function declared with 'nodiscard' attribute}} |
30 | | - ca.rend(); // expected-warning 2 {{ignoring return value of function declared with 'nodiscard' attribute}} |
31 | | - a.cbegin(); // expected-warning 2 {{ignoring return value of function declared with 'nodiscard' attribute}} |
32 | | - ca.cbegin(); // expected-warning 2 {{ignoring return value of function declared with 'nodiscard' attribute}} |
33 | | - a.cend(); // expected-warning 2 {{ignoring return value of function declared with 'nodiscard' attribute}} |
34 | | - ca.cend(); // expected-warning 2 {{ignoring return value of function declared with 'nodiscard' attribute}} |
35 | | - a.crbegin(); // expected-warning 2 {{ignoring return value of function declared with 'nodiscard' attribute}} |
36 | | - ca.crbegin(); // expected-warning 2 {{ignoring return value of function declared with 'nodiscard' attribute}} |
37 | | - a.crend(); // expected-warning 2 {{ignoring return value of function declared with 'nodiscard' attribute}} |
38 | | - ca.crend(); // expected-warning 2 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 22 | + a.begin(); // expected-warning 4 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 23 | + a.end(); // expected-warning 4 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 24 | + a.rbegin(); // expected-warning 4 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 25 | + a.rend(); // expected-warning 4 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 26 | + a.cbegin(); // expected-warning 4 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 27 | + a.cend(); // expected-warning 4 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 28 | + a.crbegin(); // expected-warning 4 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 29 | + a.crend(); // expected-warning 4 {{ignoring return value of function declared with 'nodiscard' attribute}} |
39 | 30 |
|
40 | | - a.size(); // expected-warning 2 {{ignoring return value of function declared with 'nodiscard' attribute}} |
41 | | - a.max_size(); // expected-warning 2 {{ignoring return value of function declared with 'nodiscard' attribute}} |
42 | | - a.empty(); // expected-warning 2 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 31 | + a.size(); // expected-warning 4 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 32 | + a.max_size(); // expected-warning 4 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 33 | + a.empty(); // expected-warning 4 {{ignoring return value of function declared with 'nodiscard' attribute}} |
43 | 34 |
|
44 | | - a[0]; // expected-warning 2 {{ignoring return value of function declared with 'nodiscard' attribute}} |
45 | | - ca[0]; // expected-warning 2 {{ignoring return value of function declared with 'nodiscard' attribute}} |
46 | | - a.at(0); // expected-warning 2 {{ignoring return value of function declared with 'nodiscard' attribute}} |
47 | | - ca.at(0); // expected-warning 2 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 35 | + a[0]; // expected-warning 4 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 36 | + a.at(0); // expected-warning 4 {{ignoring return value of function declared with 'nodiscard' attribute}} |
48 | 37 |
|
49 | | - a.front(); // expected-warning 2 {{ignoring return value of function declared with 'nodiscard' attribute}} |
50 | | - ca.front(); // expected-warning 2 {{ignoring return value of function declared with 'nodiscard' attribute}} |
51 | | - a.back(); // expected-warning 2 {{ignoring return value of function declared with 'nodiscard' attribute}} |
52 | | - ca.back(); // expected-warning 2 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 38 | + a.front(); // expected-warning 4 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 39 | + a.back(); // expected-warning 4 {{ignoring return value of function declared with 'nodiscard' attribute}} |
53 | 40 |
|
54 | | - a.data(); // expected-warning 2 {{ignoring return value of function declared with 'nodiscard' attribute}} |
55 | | - ca.data(); // expected-warning 2 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 41 | + a.data(); // expected-warning 4 {{ignoring return value of function declared with 'nodiscard' attribute}} |
56 | 42 | } |
57 | 43 |
|
58 | | -void test_nonmembers() { |
59 | | - { |
60 | | - std::array<int, 1> a; |
61 | | - const std::array<int, 1> ca{}; |
| 44 | +template <typename ArrT> |
| 45 | +void test_get() { |
| 46 | + ArrT a{}; |
62 | 47 |
|
63 | | - // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
64 | | - std::get<0>(a); |
65 | | - // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
66 | | - std::get<0>(ca); |
67 | | - // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
68 | | - std::get<0>(std::move(a)); |
69 | | - // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
70 | | - std::get<0>(std::move(ca)); |
71 | | - } |
| 48 | + // expected-warning@+1 2 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 49 | + std::get<0>(a); |
| 50 | + // expected-warning@+1 2 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 51 | + std::get<0>(std::move(a)); |
| 52 | +} |
72 | 53 |
|
73 | | - { |
74 | 54 | #if TEST_STD_VER >= 20 |
75 | | - // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
76 | | - std::to_array("zmt"); |
77 | | - // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
78 | | - std::to_array({94, 82, 49}); |
79 | | -#endif |
80 | | - } |
| 55 | +void test_to_array() { |
| 56 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 57 | + std::to_array("zmt"); |
| 58 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 59 | + std::to_array({94, 82, 49}); |
81 | 60 | } |
| 61 | +#endif |
82 | 62 |
|
83 | 63 | void test() { |
84 | | - test_members<0>(); |
85 | | - test_members<82>(); |
| 64 | + test_members<std::array<int, 82>>(); |
| 65 | + test_members<const std::array<int, 82>>(); |
| 66 | + test_members<std::array<int, 0>>(); |
| 67 | + test_members<const std::array<int, 0>>(); |
| 68 | + |
| 69 | + test_get<std::array<int, 82>>(); |
| 70 | + test_get<const std::array<int, 82>>(); |
86 | 71 | } |
0 commit comments