Skip to content

Commit d0b7b2e

Browse files
Enable verifying [[nodiscard]] in C++03 for various components
libc++ backports many things from C++11 to C++03, so it would be suitable to verify `[[nodiscard]]` in C++03 mode for them. Some test files are skipped because they're being touch by other patches.
1 parent 79cf27e commit d0b7b2e

18 files changed

+36
-61
lines changed

libcxx/test/libcxx/diagnostics/algorithm.nodiscard.verify.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
// UNSUPPORTED: c++03
10-
119
// check that <algorithm> functions are marked [[nodiscard]]
1210

1311
// clang-format off
@@ -188,11 +186,13 @@ void test() {
188186
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
189187
std::max(1, 2, std::greater<int>());
190188

189+
#if TEST_STD_VER >= 11
191190
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
192191
std::max({1, 2, 3});
193192

194193
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
195194
std::max({1, 2, 3}, std::greater<int>());
195+
#endif
196196

197197
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
198198
std::min_element(std::begin(arr), std::end(arr));
@@ -206,11 +206,13 @@ void test() {
206206
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
207207
std::min(1, 2, std::greater<int>());
208208

209+
#if TEST_STD_VER >= 11
209210
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
210211
std::min({1, 2, 3});
211212

212213
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
213214
std::min({1, 2, 3}, std::greater<int>());
215+
#endif
214216

215217
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
216218
std::minmax_element(std::begin(arr), std::end(arr));
@@ -224,11 +226,13 @@ void test() {
224226
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
225227
std::minmax(1, 2, std::greater<int>());
226228

229+
#if TEST_STD_VER >= 11
227230
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
228231
std::minmax({1, 2, 3});
229232

230233
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
231234
std::minmax({1, 2, 3}, std::greater<int>());
235+
#endif
232236

233237
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
234238
std::mismatch(std::begin(arr), std::end(arr), std::begin(arr));

libcxx/test/libcxx/diagnostics/array.nodiscard.verify.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
// UNSUPPORTED: c++03
10-
119
// check that <array> functions are marked [[nodiscard]]
1210

1311
#include <array>
@@ -18,7 +16,7 @@
1816
template <std::size_t N>
1917
void test_members() {
2018
std::array<int, N> a;
21-
const std::array<int, N> ca{};
19+
const std::array<int, N> ca = {};
2220

2321
a.begin(); // expected-warning 2 {{ignoring return value of function declared with 'nodiscard' attribute}}
2422
ca.begin(); // expected-warning 2 {{ignoring return value of function declared with 'nodiscard' attribute}}
@@ -57,7 +55,7 @@ void test_members() {
5755

5856
template <typename ArrT>
5957
void test_get() {
60-
std::array<int, 94> a{};
58+
std::array<int, 94> a = {};
6159

6260
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
6361
std::get<0>(a);

libcxx/test/libcxx/diagnostics/cstdlib.nodiscard.verify.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
// UNSUPPORTED: c++03
10-
119
// We don't control the implementation of the stdlib.h functions on windows
1210
// UNSUPPORTED: windows
1311

libcxx/test/libcxx/diagnostics/deque.nodiscard.verify.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
// UNSUPPORTED: c++03
10-
119
// check that <deque> functions are marked [[nodiscard]]
1210

1311
#include <deque>

libcxx/test/libcxx/diagnostics/forward_list.nodiscard.verify.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
// UNSUPPORTED: c++03
10-
119
// check that <forward_list> functions are marked [[nodiscard]]
1210

1311
#include <forward_list>

libcxx/test/libcxx/diagnostics/functional.nodiscard.verify.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
// UNSUPPORTED: c++03
10-
119
// check that <functional> functions are marked [[nodiscard]]
1210

1311
#include <cstddef>
@@ -20,7 +18,7 @@ void test() {
2018

2119
// Function wrappers
2220

23-
#if !defined(TEST_HAS_NO_RTTI)
21+
#if TEST_STD_VER >= 11 && !defined(TEST_HAS_NO_RTTI)
2422
std::function<void(int)> f;
2523
const std::function<void(int)> cf;
2624

@@ -48,14 +46,16 @@ void test() {
4846
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
4947
std::bind_front([](int a) { return a; }, 94);
5048
#endif
49+
#if TEST_STD_VER >= 11
5150
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
5251
std::bind([](int a) { return a; }, 94);
5352
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
5453
std::bind<float>([](int a) { return a; }, 94);
54+
#endif
5555

5656
// Reference wrappers
5757

58-
std::reference_wrapper<int> rw{i};
58+
std::reference_wrapper<int> rw = i;
5959
rw.get(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
6060

6161
std::ref(i); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}

libcxx/test/libcxx/diagnostics/limits.nodiscard.verify.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
// UNSUPPORTED: c++03
10-
119
// check that <limits> functions are marked [[nodiscard]]
1210

1311
#include <limits>

libcxx/test/libcxx/diagnostics/list.nodiscard.verify.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
// UNSUPPORTED: c++03
10-
119
// check that <list> functions are marked [[nodiscard]]
1210

1311
#include <list>

libcxx/test/libcxx/diagnostics/mutex.nodiscard.verify.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
// UNSUPPORTED: c++03
10-
119
// UNSUPPORTED: no-threads
1210

1311
// check that <mutex> functions are marked [[nodiscard]]
@@ -47,23 +45,23 @@ void test() {
4745
std::unique_lock<M> other;
4846

4947
// clang-format off
50-
std::unique_lock<M>{}; // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
51-
std::unique_lock<M>{m}; // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
52-
std::unique_lock<M>{m, std::defer_lock}; // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
53-
std::unique_lock<M>{m, std::try_to_lock}; // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
54-
std::unique_lock<M>{m, std::adopt_lock}; // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
55-
std::unique_lock<M>{m, time_point}; // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
56-
std::unique_lock<M>{m, duration}; // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
57-
std::unique_lock<M>(std::move(other)); // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
48+
std::unique_lock<M>(); // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
49+
(std::unique_lock<M>)(m); // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
50+
std::unique_lock<M>(m, std::defer_lock_t()); // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
51+
std::unique_lock<M>(m, std::try_to_lock_t()); // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
52+
std::unique_lock<M>(m, std::adopt_lock_t()); // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
53+
std::unique_lock<M>(m, time_point); // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
54+
std::unique_lock<M>(m, duration); // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
55+
std::unique_lock<M>(std::move(other)); // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
5856
// clang-format on
5957
}
6058

6159
// std::lock_guard
6260
{
6361
std::mutex m;
6462
// clang-format off
65-
std::lock_guard<std::mutex>{m}; // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
66-
std::lock_guard<std::mutex>{m, std::adopt_lock}; // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
63+
(std::lock_guard<std::mutex>)(m); // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
64+
std::lock_guard<std::mutex>(m, std::adopt_lock_t()); // expected-warning {{ignoring temporary created by a constructor declared with 'nodiscard' attribute}}
6765
// clang-format on
6866
}
6967
}

libcxx/test/libcxx/diagnostics/new.nodiscard.verify.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
// UNSUPPORTED: c++03
10-
119
// check that <array> functions are marked [[nodiscard]]
1210

1311
// clang-format off

0 commit comments

Comments
 (0)