1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
21 static_assert(std::semiregular
<std::identity
>);
22 static_assert(requires
{ typename
std::identity::is_transparent
; });
24 constexpr bool test() {
28 assert(id(std::move(i
)) == 42);
31 MoveOnly m2
= id(std::move(m1
));
32 assert(m2
.get() == 2);
35 static_assert(&id(id
) == &id
);
37 const std::identity idc
;
39 assert(std::move(id
)(1) == 1);
40 assert(std::move(idc
)(1) == 1);
42 id
= idc
; // run-time checks assignment
43 static_assert(std::is_same_v
<decltype(id(i
)), int&>);
44 static_assert(std::is_same_v
<decltype(id(std::declval
<int&&>())), int&&>);
46 std::is_same_v
<decltype(id(std::declval
<int const&>())), int const&>);
48 std::is_same_v
<decltype(id(std::declval
<int const&&>())), int const&&>);
49 static_assert(std::is_same_v
<decltype(id(std::declval
<int volatile&>())),
51 static_assert(std::is_same_v
<decltype(id(std::declval
<int volatile&&>())),
54 std::is_same_v
<decltype(id(std::declval
<int const volatile&>())),
55 int const volatile&>);
57 std::is_same_v
<decltype(id(std::declval
<int const volatile&&>())),
58 int const volatile&&>);
61 constexpr S() = default;
62 constexpr S(S
&&) noexcept(false) {}
63 constexpr S(S
const&) noexcept(false) {}
66 static_assert(noexcept(id(x
)));
67 static_assert(noexcept(id(S())));
72 int main(int, char**) {
74 static_assert(test());