• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <utility> functions are marked [[nodiscard]]
12 
13 // clang-format off
14 
15 #include <utility>
16 
17 #include "test_macros.h"
18 
test()19 void test() {
20   int i = 0;
21 
22   std::forward<int>(i);     // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
23   std::forward<int>(1);     // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
24   std::move(i);             // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
25   std::move_if_noexcept(i); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
26 
27 #if TEST_STD_VER >= 17
28   std::as_const(i); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
29 #endif
30 
31 #if TEST_STD_VER >= 23
32   enum E { Apple, Orange } e = Apple;
33   std::to_underlying(e); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
34 #endif
35 }
36