xref: /llvm-project/libcxx/test/libcxx/diagnostics/new.nodiscard.verify.cpp (revision ba87515fea90b5d55836a8e3be63a7e683ce299d)
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 // UNSUPPORTED: c++03
10 
11 // check that <array> functions are marked [[nodiscard]]
12 
13 // clang-format off
14 
15 #include <new>
16 
17 #include "test_macros.h"
18 
19 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}}
24 #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}}
29 #endif // _LIBCPP_HAS_ALIGNED_ALLOCATION
30 
31 #if TEST_STD_VER >= 17
32   int* ptr = nullptr;
33   std::launder(ptr); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
34 #endif
35 }
36