-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA12-7-1.cpp
More file actions
114 lines (84 loc) · 2.14 KB
/
A12-7-1.cpp
File metadata and controls
114 lines (84 loc) · 2.14 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
110
111
112
113
114
// Rule: A12-7-1
// Source line: 17956
// Original file: A12-7-1.cpp
// $Id: A12-7-1.cpp 271715 2017-03-23 10:13:51Z piotr.tanski $
#include <cstdint>
#include <utility>
class A
{
public:
A() : x(0), y(0) {} // Compliant
A(std::int32_t first, std::int32_t second) : x(first), y(second) {}
Compliant
// -
//
// anyway, such
// a constructor
// cannot be
// defaulted.
A(const A& oth)
: x(oth.x),
y(oth.y) // Non-compliant - equivalent to the implicitly
// defined copy constructor
{}
A(A&& oth)
: x(std::move(oth.x)),
y(std::move(
oth.y)) // Non-compliant - equivalent to the implicitly
// defined move constructor
{}
~A() // Non-compliant - equivalent to the implicitly defined destructor
{}
private:
std::int32_t x;
std::int32_t y;
};
class B
{
public:
B() {}
// Non-compliant - x and y are not initialized
// should be replaced with: B() : x{0}, y{0} {}
B(std::int32_t first, std::int32_t second) : x(first), y(second) {} //
Compliant
B(const B&) =
default; // Compliant - equivalent to the copy constructor of class A
B(B&&) =
default; // Compliant - equivalent to the move constructor of class A
~B() = default; // Compliant - equivalent to the destructor of class A
private:
std::int32_t x;
std::int32_t y;
};
class C
{
public:
C() = default;
C(const C&) = default;
C(C&&) = default;
};
class D
{
public:
D() : ptr(nullptr) {}
// Compliant
// Compliant
// Compliant
// Compliant - this is not equivalent to what the
// implicitly defined default constructor would do
D(C* p) : ptr(p) {}
// Compliant
D(const D&) = default; // Shallow copy will be performed, user-defined copy
// constructor is needed to perform deep copy on ptr variable
D(D&&) = default; // ptr variable will be moved, so ptr will still point to
// the same object
~D() = default;
// ptr will not be deleted, the user-defined destructor is
// needed to delete allocated memory
private:
C* ptr;
};
class E
// Compliant - special member functions definitions are not needed as
// class E uses only implicit definitions
{};