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 <memory> functions are marked [[nodiscard]] 12 13 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_CXX20_REMOVED_TEMPORARY_BUFFER 14 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS 15 16 // clang-format off 17 18 #include <memory> 19 20 #include "test_macros.h" 21 22 void test() { 23 std::get_temporary_buffer<int>(0); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} 24 } 25 26 void test_allocator_traits() { 27 std::allocator<int> allocator; 28 std::allocator_traits<std::allocator<int>> allocator_traits; 29 allocator_traits.allocate(allocator, 1); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} 30 allocator_traits.allocate(allocator, 1, nullptr); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} 31 } 32 33 void test_allocator() { 34 std::allocator<int> allocator; 35 allocator.allocate(1); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} 36 #if TEST_STD_VER <= 17 37 allocator.allocate(1, nullptr); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} 38 #endif 39 #if TEST_STD_VER >= 23 40 allocator.allocate_at_least(1); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} 41 #endif 42 } 43