Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / utilities / meta / meta.unary / meta.unary.prop / is_nothrow_swappable.pass.cpp
blob84742f755a6b4f7600d2b6fcf9faa6b9054def72
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
11 // type_traits
13 // is_swappable
15 #include <type_traits>
16 #include <vector>
17 #include "test_macros.h"
19 namespace MyNS {
21 // Make the test types non-copyable so that generic std::swap is not valid.
22 struct A {
23 A(A const&) = delete;
24 A& operator=(A const&) = delete;
27 struct B {
28 B(B const&) = delete;
29 B& operator=(B const&) = delete;
32 void swap(A&, A&) noexcept {}
33 void swap(B&, B&) {}
35 struct M {
36 M(M const&) = delete;
37 M& operator=(M const&) = delete;
40 void swap(M&&, M&&) noexcept {}
42 struct ThrowingMove {
43 ThrowingMove(ThrowingMove&&) {}
44 ThrowingMove& operator=(ThrowingMove&&) { return *this; }
47 } // namespace MyNS
49 int main(int, char**)
51 using namespace MyNS;
53 // Test that is_swappable applies an lvalue reference to the type.
54 static_assert(std::is_nothrow_swappable<int>::value, "");
55 static_assert(std::is_nothrow_swappable<int&>::value, "");
56 static_assert(!std::is_nothrow_swappable<M>::value, "");
57 static_assert(!std::is_nothrow_swappable<M&&>::value, "");
60 // Test that it correctly deduces the noexcept of swap.
61 static_assert(std::is_nothrow_swappable<A>::value, "");
62 static_assert(!std::is_nothrow_swappable<B>::value
63 && std::is_swappable<B>::value, "");
64 static_assert(!std::is_nothrow_swappable<ThrowingMove>::value
65 && std::is_swappable<ThrowingMove>::value, "");
68 // Test that it doesn't drop the qualifiers
69 static_assert(!std::is_nothrow_swappable<const A>::value, "");
72 // test non-referenceable types
73 static_assert(!std::is_nothrow_swappable<void>::value, "");
74 static_assert(!std::is_nothrow_swappable<int() const>::value, "");
75 static_assert(!std::is_nothrow_swappable<int(int, ...) const &>::value, "");
78 // test for presence of is_nothrow_swappable_v
79 static_assert(std::is_nothrow_swappable_v<int>, "");
80 static_assert(!std::is_nothrow_swappable_v<void>, "");
83 return 0;