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 // check that <bit> functions are marked [[nodiscard]]
12
13 // clang-format off
14
15 #include <bit>
16
17 #include "test_macros.h"
18
func()19 void func() {
20 std::bit_cast<unsigned int>(42); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
21 std::bit_ceil(0u); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
22 std::bit_floor(0u); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
23 std::bit_width(0u); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
24 #if TEST_STD_VER >= 23
25 std::byteswap(0u); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
26 #endif
27 std::countl_zero(0u); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
28 std::countl_one(0u); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
29 std::countr_zero(0u); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
30 std::countr_one(0u); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
31 std::has_single_bit(0u); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
32 std::popcount(0u); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
33 }
34