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// UNSUPPORTED: (c++11 || c++14 || c++17) && !stdlib=libc++
11
12// Make sure the various node handles mark their .empty() method with
13// [[nodiscard]] starting with C++20
14
15#include <map>
16#include <set>
17#include <unordered_map>
18#include <unordered_set>
19
20#include "test_macros.h"
21
22void test() {
23#if TEST_STD_VER >= 17
24 {
25 std::map<int, int>::node_type node;
26 node.empty(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
27 }
28 {
29 std::multimap<int, int>::node_type node;
30 node.empty(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
31 }
32#endif // TEST_STD_VER >= 17
33 {
34 std::set<int> node;
35 node.empty(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
36 }
37 {
38 std::multiset<int> node;
39 node.empty(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
40 }
41 {
42 std::unordered_map<int, int> node;
43 node.empty(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
44 }
45 {
46 std::unordered_multimap<int, int> node;
47 node.empty(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
48 }
49 {
50 std::unordered_set<int> node;
51 node.empty(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
52 }
53 {
54 std::unordered_multiset<int> node;
55 node.empty(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
56 }
57}
58

source code of libcxx/test/std/containers/container.node/node_handle.nodiscard.verify.cpp