Repository navigation
Expand file tree
/
Copy pathtest.cpp
More file actions
94 lines (74 loc) · 4.2 KB
/
Copy pathtest.cpp
File metadata and controls
94 lines (74 loc) · 4.2 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
#include <cstdint>
#include <iostream>
class TestClass {
std::int32_t value;
public:
TestClass(std::int32_t v = 0) : value(v) {}
// NON-COMPLIANT: Symmetrical operators as member functions
TestClass operator+(const TestClass &rhs) const; // NON_COMPLIANT
TestClass operator-(const TestClass &rhs) const; // NON_COMPLIANT
TestClass operator*(const TestClass &rhs) const; // NON_COMPLIANT
TestClass operator/(const TestClass &rhs) const; // NON_COMPLIANT
TestClass operator%(const TestClass &rhs) const; // NON_COMPLIANT
bool operator==(const TestClass &rhs) const; // NON_COMPLIANT
bool operator!=(const TestClass &rhs) const; // NON_COMPLIANT
bool operator<(const TestClass &rhs) const; // NON_COMPLIANT
bool operator<=(const TestClass &rhs) const; // NON_COMPLIANT
bool operator>=(const TestClass &rhs) const; // NON_COMPLIANT
bool operator>(const TestClass &rhs) const; // NON_COMPLIANT
TestClass operator^(const TestClass &rhs) const; // NON_COMPLIANT
TestClass operator&(const TestClass &rhs) const; // NON_COMPLIANT
TestClass operator|(const TestClass &rhs) const; // NON_COMPLIANT
bool operator&&(const TestClass &rhs) const; // NON_COMPLIANT
bool operator||(const TestClass &rhs) const; // NON_COMPLIANT
// NON-COMPLIANT: Mixed type symmetrical operators as members
TestClass operator+(std::int32_t rhs) const; // NON_COMPLIANT
bool operator==(std::int32_t rhs) const; // NON_COMPLIANT
// COMPLIANT: Hidden friend operators (non-member but defined in class)
friend TestClass operator+(const TestClass &lhs,
const TestClass &rhs) { // COMPLIANT
return TestClass(lhs.value + rhs.value);
}
friend bool operator==(const TestClass &lhs,
const TestClass &rhs) { // COMPLIANT
return lhs.value == rhs.value;
}
// COMPLIANT: Non-symmetrical operators as members are allowed
TestClass &operator+=(const TestClass &rhs); // COMPLIANT
TestClass &operator-=(const TestClass &rhs); // COMPLIANT
TestClass &operator*=(const TestClass &rhs); // COMPLIANT
TestClass &operator/=(const TestClass &rhs); // COMPLIANT
TestClass &operator%=(const TestClass &rhs); // COMPLIANT
TestClass &operator^=(const TestClass &rhs); // COMPLIANT
TestClass &operator&=(const TestClass &rhs); // COMPLIANT
TestClass &operator|=(const TestClass &rhs); // COMPLIANT
TestClass &operator++(); // COMPLIANT
TestClass operator++(int); // COMPLIANT
TestClass &operator--(); // COMPLIANT
TestClass operator--(int); // COMPLIANT
TestClass operator~() const; // COMPLIANT
bool operator!() const; // COMPLIANT
TestClass &operator=(const TestClass &rhs); // COMPLIANT
// COMPLIANT: Stream operators are not symmetrical
friend std::ostream &operator<<(std::ostream &os,
const TestClass &tc); // COMPLIANT
friend std::istream &operator>>(std::istream &is, TestClass &tc); // COMPLIANT
};
// COMPLIANT: Non-member symmetrical operators
TestClass operator-(const TestClass &lhs, const TestClass &rhs); // COMPLIANT
TestClass operator*(const TestClass &lhs, const TestClass &rhs); // COMPLIANT
TestClass operator/(const TestClass &lhs, const TestClass &rhs); // COMPLIANT
TestClass operator%(const TestClass &lhs, const TestClass &rhs); // COMPLIANT
bool operator!=(const TestClass &lhs, const TestClass &rhs); // COMPLIANT
bool operator<(const TestClass &lhs, const TestClass &rhs); // COMPLIANT
bool operator<=(const TestClass &lhs, const TestClass &rhs); // COMPLIANT
bool operator>=(const TestClass &lhs, const TestClass &rhs); // COMPLIANT
bool operator>(const TestClass &lhs, const TestClass &rhs); // COMPLIANT
TestClass operator^(const TestClass &lhs, const TestClass &rhs); // COMPLIANT
TestClass operator&(const TestClass &lhs, const TestClass &rhs); // COMPLIANT
TestClass operator|(const TestClass &lhs, const TestClass &rhs); // COMPLIANT
bool operator&&(const TestClass &lhs, const TestClass &rhs); // COMPLIANT
bool operator||(const TestClass &lhs, const TestClass &rhs); // COMPLIANT
// COMPLIANT: Mixed type non-member symmetrical operators
TestClass operator+(const TestClass &lhs, std::int32_t rhs); // COMPLIANT
TestClass operator+(std::int32_t lhs, const TestClass &rhs); // COMPLIANT