-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA11-0-1.cpp
More file actions
74 lines (59 loc) · 1.56 KB
/
A11-0-1.cpp
File metadata and controls
74 lines (59 loc) · 1.56 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
// Rule: A11-0-1
// Source line: 16106
// Original file: A11-0-1.cpp
// $Id: A11-0-1.cpp 289436 2017-10-04 10:45:23Z michal.szczepankiewicz $
#include <cstdint>
#include <limits>
class A // Compliant - A provides user-defined constructors, invariant and
// interface
{
std::int32_t x; // Data member is private by default
public:
static constexpr std::int32_t maxValue =
std::numeric_limits<std::int32_t>::max();
A() : x(maxValue) {}
explicit A(std::int32_t number) : x(number) {}
A(A const&) = default;
A(A&&) = default;
A& operator=(A const&) = default;
A& operator=(A&&) = default;
std::int32_t GetX() const noexcept {
return x;
}
void SetX(std::int32_t number) noexcept {
x = number;
}
};
struct B // Non-compliant - non-POD type defined as struct
{
public:
static constexpr std::int32_t maxValue =
std::numeric_limits<std::int32_t>::max();
B() : x(maxValue) {}
explicit B(std::int32_t number) : x(number) {}
B(B const&) = default;
B(B&&) = default;
B& operator=(B const&) = default;
B& operator=(B&&) = default;
std::int32_t GetX() const noexcept {
return x;
}
void SetX(std::int32_t number) noexcept {
x = number;
}
private:
std::int32_t x;
// Need to provide private access specifier for x member
};
struct C // Compliant - POD type defined as struct
{
std::int32_t x;
std::int32_t y;
};
class D // Compliant - POD type defined as class, but not compliant with
// M11-0-1
{
public:
std::int32_t x;
std::int32_t y;
};