Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / iterators / predef.iterators / move.iterators / move.sentinel / assign.converting.pass.cpp
blobaa81390e1ec0c212b8bef50f2ff583b50aafbb91
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 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
11 // <iterator>
13 // move_sentinel
15 // template<class S2>
16 // requires assignable_from<S&, const S2&>
17 // constexpr move_sentinel& operator=(const move_sentinel<S2>& s);
19 #include <cassert>
20 #include <concepts>
21 #include <iterator>
22 #include <type_traits>
24 struct NonAssignable {
25 NonAssignable& operator=(int i);
27 static_assert(std::semiregular<NonAssignable>);
28 static_assert(std::is_assignable_v<NonAssignable, int>);
29 static_assert(!std::assignable_from<NonAssignable, int>);
31 constexpr bool test()
33 // Assigning from an lvalue.
35 std::move_sentinel<int> m(42);
36 std::move_sentinel<long> m2;
37 m2 = m;
38 assert(m2.base() == 42L);
41 // Assigning from an rvalue.
43 std::move_sentinel<long> m2;
44 m2 = std::move_sentinel<int>(43);
45 assert(m2.base() == 43L);
48 // SFINAE checks.
50 static_assert( std::is_assignable_v<std::move_sentinel<int>, std::move_sentinel<long>>);
51 static_assert(!std::is_assignable_v<std::move_sentinel<int*>, std::move_sentinel<const int*>>);
52 static_assert( std::is_assignable_v<std::move_sentinel<const int*>, std::move_sentinel<int*>>);
53 static_assert(!std::is_assignable_v<std::move_sentinel<NonAssignable>, std::move_sentinel<int>>);
55 return true;
58 int main(int, char**)
60 test();
61 static_assert(test());
63 return 0;