cppcoreguidelines-special-member-functions-relaxed.cpp
3.31 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
// RUN: %check_clang_tidy %s cppcoreguidelines-special-member-functions %t -- -config="{CheckOptions: [{key: cppcoreguidelines-special-member-functions.AllowMissingMoveFunctions, value: 1}, {key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor, value: 1}]}" --
class DefinesDestructor {
~DefinesDestructor();
};
// CHECK-MESSAGES: [[@LINE-3]]:7: warning: class 'DefinesDestructor' defines a non-default destructor but does not define a copy constructor or a copy assignment operator [cppcoreguidelines-special-member-functions]
class DefinesDefaultedDestructor {
~DefinesDefaultedDestructor() = default;
};
class DefinesCopyConstructor {
DefinesCopyConstructor(const DefinesCopyConstructor &);
};
// CHECK-MESSAGES: [[@LINE-3]]:7: warning: class 'DefinesCopyConstructor' defines a copy constructor but does not define a destructor or a copy assignment operator [cppcoreguidelines-special-member-functions]
class DefinesCopyAssignment {
DefinesCopyAssignment &operator=(const DefinesCopyAssignment &);
};
// CHECK-MESSAGES: [[@LINE-3]]:7: warning: class 'DefinesCopyAssignment' defines a copy assignment operator but does not define a destructor or a copy constructor [cppcoreguidelines-special-member-functions]
class DefinesMoveConstructor {
DefinesMoveConstructor(DefinesMoveConstructor &&);
};
// CHECK-MESSAGES: [[@LINE-3]]:7: warning: class 'DefinesMoveConstructor' defines a move constructor but does not define a destructor, a copy constructor, a copy assignment operator or a move assignment operator [cppcoreguidelines-special-member-functions]
class DefinesMoveAssignment {
DefinesMoveAssignment &operator=(DefinesMoveAssignment &&);
};
// CHECK-MESSAGES: [[@LINE-3]]:7: warning: class 'DefinesMoveAssignment' defines a move assignment operator but does not define a destructor, a copy constructor, a copy assignment operator or a move constructor [cppcoreguidelines-special-member-functions]
class DefinesNothing {
};
class DefinesEverything {
DefinesEverything(const DefinesEverything &);
DefinesEverything &operator=(const DefinesEverything &);
DefinesEverything(DefinesEverything &&);
DefinesEverything &operator=(DefinesEverything &&);
~DefinesEverything();
};
class DeletesEverything {
DeletesEverything(const DeletesEverything &) = delete;
DeletesEverything &operator=(const DeletesEverything &) = delete;
DeletesEverything(DeletesEverything &&) = delete;
DeletesEverything &operator=(DeletesEverything &&) = delete;
~DeletesEverything() = delete;
};
class DeletesCopyDefaultsMove {
DeletesCopyDefaultsMove(const DeletesCopyDefaultsMove &) = delete;
DeletesCopyDefaultsMove &operator=(const DeletesCopyDefaultsMove &) = delete;
DeletesCopyDefaultsMove(DeletesCopyDefaultsMove &&) = default;
DeletesCopyDefaultsMove &operator=(DeletesCopyDefaultsMove &&) = default;
~DeletesCopyDefaultsMove() = default;
};
template <typename T>
struct TemplateClass {
TemplateClass() = default;
TemplateClass(const TemplateClass &);
TemplateClass &operator=(const TemplateClass &);
TemplateClass(TemplateClass &&);
TemplateClass &operator=(TemplateClass &&);
~TemplateClass();
};
// Multiple instantiations of a class template will trigger multiple matches for defined special members.
// This should not cause problems.
TemplateClass<int> InstantiationWithInt;
TemplateClass<double> InstantiationWithDouble;