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 // We get availability markup errors when aligned allocation is missing
21 // XFAIL: availability-aligned_allocation-missing
22 
23 // Libc++ when built for z/OS doesn't contain the aligned allocation functions,
24 // nor does the dynamic library shipped with z/OS.
25 // UNSUPPORTED: target={{.+}}-zos{{.*}}
26 
27 #include <new>
28 
29 #include "test_macros.h"
30 
31 void f() {
32     ::operator new[](4);  // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
33     ::operator new[](4, std::nothrow);  // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
34 
35 #if TEST_STD_VER >= 17
36     ::operator new[](4, std::align_val_t{4});  // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
37     ::operator new[](4, std::align_val_t{4}, std::nothrow);  // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
38 #endif
39 }
40