1 | //===----------------------------------------------------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | // [[nodiscard]] void* operator new[](std::size_t); |
10 | // [[nodiscard]] void* operator new[](std::size_t, std::nothrow_t const&); |
11 | // [[nodiscard]] void* operator new[](std::size_t, std::align_val_t); |
12 | // [[nodiscard]] void* operator new[](std::size_t, std::align_val_t, std::nothrow_t const&); |
13 | |
14 | // [[nodiscard]] is not supported at all in c++03 |
15 | // UNSUPPORTED: c++03 |
16 | |
17 | // [[nodiscard]] enabled before C++20 in libc++ as an extension |
18 | // UNSUPPORTED: (c++11 || c++14 || c++17) && !stdlib=libc++ |
19 | |
20 | // Libc++ when built for z/OS doesn't contain the aligned allocation functions, |
21 | // nor does the dynamic library shipped with z/OS. |
22 | // XFAIL: target={{.+}}-zos{{.*}} |
23 | |
24 | #include <new> |
25 | |
26 | #include "test_macros.h" |
27 | |
28 | void f() { |
29 | ::operator new[](4); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
30 | ::operator new[](4, std::nothrow); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
31 | |
32 | #if TEST_STD_VER >= 17 |
33 | ::operator new[](4, std::align_val_t{4}); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
34 | ::operator new[](4, std::align_val_t{4}, std::nothrow); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
35 | #endif |
36 | } |
37 | |