-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA14-1-1.cpp
More file actions
109 lines (90 loc) · 2.43 KB
/
A14-1-1.cpp
File metadata and controls
109 lines (90 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Rule: A14-1-1
// Source line: 20507
// Original file: A14-1-1.cpp
// $Id: A14-1-1.cpp 289436 2017-10-04 10:45:23Z michal.szczepankiewicz $
#include <utility>
class A
{
public:
A() = default;
~A() = default;
A(A const&) = delete;
A& operator=(A const&) = delete;
A(A&&) = delete;
A& operator=(A&&) = delete;
};
class B
{
public:
B() = default;
B(B const&) = default;
B& operator=(B const&) = default;
B(B&&) = default;
B& operator=(B&&) = default;
};
template<typename T>
void F1(T const& obj) noexcept(false)
{
static_assert(
std::is_copy_constructible<T>(),
"Given template type is not copy constructible."); // Compliant
}
template<typename T>
class C
{
// Compliant
static_assert(std::is_trivially_copy_constructible<T>(),
"Given template type is not trivially copy constructible.");
// Compliant
static_assert(std::is_trivially_move_constructible<T>(),
"Given template type is not trivially move constructible.");
// Compliant
static_assert(std::is_trivially_copy_assignable<T>(),
"Given template type is not trivially copy assignable.");
// Compliant
static_assert(std::is_trivially_move_assignable<T>(),
"Given template type is not trivially move assignable.");
public:
C() = default;
C(C const&) = default;
C& operator=(C const&) = default;
C(C&&) = default;
C& operator=(C&&) = default;
private:
T c;
};
template<typename T>
class D
{
public:
D() = default;
D(D const&) = default;
D& operator=(D const&) = default;
D(D&&) = default;
D& operator=(D&&) = default;
// Non-compliant - T may not be copyable
// Non-compliant - T may not be copyable
// Non-compliant - T may not be movable
// Non-compliant - T may not be movable
private:
T d;
};
void F2() noexcept
{
A a;
B b;
// f1<A>(a); // Class A is not copy constructible, compile-time error
// occurs
F1<B>(b); // Class B is copy constructible
// C<A> c1; // Class A can not be used for template class C, compile-time
// error occurs
C<B> c2; // Class B can be used for template class C
D<A> d1;
// D<A> d2 = d1; // Class D can not be copied, because class A is not
// copyable, compile=time error occurs
// D<A> d3 = std::move(d1); // Class D can not be moved, because class A is
// not movable, compile-time error occurs
D<B> d4;
D<B> d5 = d4;
D<B> d6 = std::move(d4);
}