| 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 [[nodiscard]] extension in libc++. |
| 12 | |
| 13 | // template<class I> |
| 14 | // unspecified iter_move; |
| 15 | |
| 16 | #include <iterator> |
| 17 | |
| 18 | struct WithADL { |
| 19 | WithADL() = default; |
| 20 | constexpr decltype(auto) operator*() const noexcept; |
| 21 | constexpr WithADL& operator++() noexcept; |
| 22 | constexpr void operator++(int) noexcept; |
| 23 | constexpr bool operator==(WithADL const&) const noexcept; |
| 24 | friend constexpr auto iter_move(WithADL&) { return 0; } |
| 25 | }; |
| 26 | |
| 27 | void f() { |
| 28 | int* noADL = nullptr; |
| 29 | std::ranges::iter_move(noADL); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 30 | |
| 31 | WithADL adl; |
| 32 | std::ranges::iter_move(adl); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} |
| 33 | } |
| 34 | |