-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathtest.cpp
More file actions
52 lines (40 loc) · 1.32 KB
/
test.cpp
File metadata and controls
52 lines (40 loc) · 1.32 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
class Base {
virtual void foo() {}
};
class BaseWithVirtualDestructor {
public:
virtual void bar() {}
virtual ~BaseWithVirtualDestructor() = default;
};
class DerivedA : public Base {
void foo() {
delete this; // NON_COMPLIANT
}
};
class DerivedB final : public DerivedA {
void foo() {
delete this; // COMPLIANT
}
};
class DerivedC : public BaseWithVirtualDestructor {
void bar() {
delete this; // COMPLIANT
}
};
void test() {
DerivedA *a1 = new DerivedA(); // COMPLIANT
DerivedB *b1 = new DerivedB(); // COMPLIANT
a1 = (DerivedA *)b1; // NON_COMPLIANT
DerivedA *a2 = nullptr; // COMPLIANT
DerivedC *c1 = new DerivedC(); // COMPLIANT
a2 = (DerivedA *)new DerivedB(); // NON_COMPLIANT
Base *d1 = new Base(); // COMPLIANT
/* std::unique_ptr<Base> ptr1 = std::make_unique<Base>(); // COMPLIANT
std::unique_ptr<DerivedA> ptr3 = std::make_unique<DerivedA>(); // COMPLIANT
std::unique_ptr<DerivedB> ptr4 = std::make_unique<DerivedB>(); // COMPLIANT
std::unique_ptr<DerivedC> ptr5 = std::make_unique<DerivedC>(); // COMPLIANT
std::unique_ptr<BaseWithVirtualDestructor> ptr6 =
std::make_unique<DerivedC>(); // COMPLIANT
std::unique_ptr<DerivedA> ptr7(a1); // COMPLIANT
std::unique_ptr<DerivedA> ptr8(b1); // NON_COMPLIANT */
}