|
6 | 6 | // |
7 | 7 | //===----------------------------------------------------------------------===// |
8 | 8 |
|
9 | | -// UNSUPPORTED: c++03 |
| 9 | +// <new> |
10 | 10 |
|
11 | | -// check that <array> functions are marked [[nodiscard]] |
12 | | - |
13 | | -// clang-format off |
| 11 | +// Check that functions are marked [[nodiscard]] |
14 | 12 |
|
15 | 13 | #include <new> |
16 | 14 |
|
17 | 15 | #include "test_macros.h" |
18 | 16 |
|
19 | 17 | void test() { |
20 | | - ::operator new(0); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
21 | | - ::operator new(0, std::nothrow); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
22 | | - ::operator new[](0); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
23 | | - ::operator new[](0, std::nothrow); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 18 | + { |
| 19 | + std::bad_alloc ex; |
| 20 | + |
| 21 | + ex.what(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 22 | + } |
| 23 | + { |
| 24 | + std::bad_array_new_length ex; |
| 25 | + |
| 26 | + ex.what(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 27 | + } |
| 28 | + |
| 29 | + { |
| 30 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 31 | + ::operator new(0); |
| 32 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 33 | + ::operator new(0, std::nothrow); |
| 34 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 35 | + ::operator new[](0); |
| 36 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 37 | + ::operator new[](0, std::nothrow); |
24 | 38 | #if _LIBCPP_HAS_ALIGNED_ALLOCATION |
25 | | - ::operator new(0, std::align_val_t{1}); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
26 | | - ::operator new(0, std::align_val_t{1}, std::nothrow); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
27 | | - ::operator new[](0, std::align_val_t{1}); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
28 | | - ::operator new[](0, std::align_val_t{1}, std::nothrow); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 39 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 40 | + ::operator new(0, std::align_val_t{1}); |
| 41 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 42 | + ::operator new(0, std::align_val_t{1}, std::nothrow); |
| 43 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 44 | + ::operator new[](0, std::align_val_t{1}); |
| 45 | + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 46 | + ::operator new[](0, std::align_val_t{1}, std::nothrow); |
29 | 47 | #endif // _LIBCPP_HAS_ALIGNED_ALLOCATION |
| 48 | + } |
| 49 | + |
| 50 | +#if !defined(TEST_HAS_NO_ABI_VCRUNTIME) |
| 51 | + // FIXME: When libc++ is linked against vcruntime (i.e. the default config in |
| 52 | + // MSVC mode), the declarations of std::set_new_handler and std::get_new_handler |
| 53 | + // are provided by vcruntime/UCRT's new.h. However, that header actually only |
| 54 | + // declares set_new_handler - it's missing a declaration of get_new_handler. |
| 55 | + std::get_new_handler(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 56 | +#endif |
30 | 57 |
|
31 | 58 | #if TEST_STD_VER >= 17 |
32 | | - int* ptr = nullptr; |
33 | | - std::launder(ptr); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 59 | + { |
| 60 | + int* ptr = nullptr; |
| 61 | + |
| 62 | + std::launder(ptr); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 63 | + } |
34 | 64 | #endif |
35 | 65 | } |
0 commit comments