-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA12-8-1.cpp
More file actions
89 lines (63 loc) · 1.26 KB
/
A12-8-1.cpp
File metadata and controls
89 lines (63 loc) · 1.26 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
// Rule: A12-8-1
// Source line: 18183
// Original file: A12-8-1.cpp
// $Id: A12-8-1.cpp 303582 2018-01-11 13:42:56Z michal.szczepankiewicz $
#include <cstdint>
#include <utility>
class A
{
public:
// Implementation
A(A const& oth) : x(oth.x) // Compliant
{}
private:
std::int32_t x;
};
class B
{
public:
// Implementation
B(B&& oth) : ptr(std::move(oth.ptr)) // Compliant
{
oth.ptr = nullptr; // Compliant - this is not a side-effect, in this
// case it is essential to leave moved-from object
// in a valid state, otherwise double deletion will
// occur.
}
~B() {
delete ptr;
}
private:
std::int32_t* ptr;
};
class C
{
public:
// Implementation
C(C const& oth) : x(oth.x)
{
// ...
x = x % 2; // Non-compliant - unrelated side-effect
}
private:
std::int32_t x;
};
class D
{
public:
explicit D(std::uint32_t a) : a(a), noOfModifications(0) {}
D(const D& d) : D(d.a) {} //compliant, not copying the debug information
about number of modifications
void SetA(std::uint32_t aa)
{
++noOfModifications;
a = aa;
}
std::uint32_t GetA() const noexcept
{
return a;
}
private:
std::uint32_t a;
std::uint64_t noOfModifications;
};