xref: /llvm-project/libcxx/test/libcxx/ranges/range.adaptors/range.transform/adaptor.nodiscard.verify.cpp (revision b8cb1dc9ea87faa8e8e9ab7a31710a8c0bb8b084)
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, c++11, c++14, c++17
10 
11 // Test the libc++ extension that std::views::transform is marked as [[nodiscard]].
12 
13 #include <ranges>
14 
test()15 void test() {
16   int range[] = {1, 2, 3};
17   auto f = [](int i) { return i; };
18 
19   std::views::transform(f); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
20   std::views::transform(range, f); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
21   range | std::views::transform(f); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
22   std::views::all | std::views::transform(f); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
23 }
24