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 // Check that ranges are marked [[nodiscard]] as a conforming extension
10
11 // UNSUPPORTED: c++03, c++11, c++14, c++17
12
13 // clang-format off
14
15 #include <ranges>
16 #include <functional>
17 #include <vector>
18
19 #include "test_macros.h"
20
test()21 void test() {
22 std::vector<int> range;
23 std::ranges::less_equal pred;
24
25 std::views::drop(pred); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
26
27 std::views::split(range, 3); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
28 std::views::split(1); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
29
30 std::views::take(range, 3); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
31 std::views::take(1); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
32
33 #if TEST_STD_VER >= 23
34 std::views::drop(std::views::repeat(1)); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
35
36 std::views::repeat(1); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
37 std::views::repeat(1, std::unreachable_sentinel); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
38
39 auto rvalue_view = std::views::as_rvalue(range);
40 std::views::as_rvalue(range); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
41 std::views::as_rvalue(rvalue_view); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
42
43 std::views::chunk_by(pred); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
44 std::views::chunk_by(range, pred); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
45
46 std::views::take(std::views::repeat(3), 3); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
47 std::views::take(std::views::repeat(3, std::unreachable_sentinel), 3); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
48
49 std::allocator<int> alloc;
50
51 std::ranges::to<std::vector<int>>(range); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
52 std::ranges::to<std::vector<int>>(range, alloc); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
53 std::ranges::to<std::vector>(range); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
54 std::ranges::to<std::vector>(range, alloc); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
55 range | std::ranges::to<std::vector<int>>(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
56 range | std::ranges::to<std::vector<int>>(alloc); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
57 range | std::ranges::to<std::vector>(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
58 range | std::ranges::to<std::vector>(alloc); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
59 #endif // TEST_STD_VER >= 23
60 }
61