1// RUN: %check_clang_tidy %s cppcoreguidelines-special-member-functions %t -- -config="{CheckOptions: {cppcoreguidelines-special-member-functions.AllowMissingMoveFunctions: true, cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor: true}}" --
2
3// Don't warn on destructors without definitions, they might be defaulted in another TU.
4class DeclaresDestructor {
5 ~DeclaresDestructor();
6};
7
8class DefinesDestructor {
9 ~DefinesDestructor();
10};
11DefinesDestructor::~DefinesDestructor() {}
12// CHECK-MESSAGES: [[@LINE-4]]: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]
13
14class DefinesDefaultedDestructor {
15 ~DefinesDefaultedDestructor() = default;
16};
17
18class DefinesDefaultedDestructorOutside {
19 ~DefinesDefaultedDestructorOutside();
20};
21
22DefinesDefaultedDestructorOutside::~DefinesDefaultedDestructorOutside() = default;
23
24class DefinesCopyConstructor {
25 DefinesCopyConstructor(const DefinesCopyConstructor &);
26};
27// 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]
28
29class DefinesCopyAssignment {
30 DefinesCopyAssignment &operator=(const DefinesCopyAssignment &);
31};
32// 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]
33
34class DefinesMoveConstructor {
35 DefinesMoveConstructor(DefinesMoveConstructor &&);
36};
37// 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]
38
39class DefinesMoveAssignment {
40 DefinesMoveAssignment &operator=(DefinesMoveAssignment &&);
41};
42// 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]
43class DefinesNothing {
44};
45
46class DefinesEverything {
47 DefinesEverything(const DefinesEverything &);
48 DefinesEverything &operator=(const DefinesEverything &);
49 DefinesEverything(DefinesEverything &&);
50 DefinesEverything &operator=(DefinesEverything &&);
51 ~DefinesEverything();
52};
53
54class DeletesEverything {
55 DeletesEverything(const DeletesEverything &) = delete;
56 DeletesEverything &operator=(const DeletesEverything &) = delete;
57 DeletesEverything(DeletesEverything &&) = delete;
58 DeletesEverything &operator=(DeletesEverything &&) = delete;
59 ~DeletesEverything() = delete;
60};
61
62class DeletesCopyDefaultsMove {
63 DeletesCopyDefaultsMove(const DeletesCopyDefaultsMove &) = delete;
64 DeletesCopyDefaultsMove &operator=(const DeletesCopyDefaultsMove &) = delete;
65 DeletesCopyDefaultsMove(DeletesCopyDefaultsMove &&) = default;
66 DeletesCopyDefaultsMove &operator=(DeletesCopyDefaultsMove &&) = default;
67 ~DeletesCopyDefaultsMove() = default;
68};
69
70template <typename T>
71struct TemplateClass {
72 TemplateClass() = default;
73 TemplateClass(const TemplateClass &);
74 TemplateClass &operator=(const TemplateClass &);
75 TemplateClass(TemplateClass &&);
76 TemplateClass &operator=(TemplateClass &&);
77 ~TemplateClass();
78};
79
80// Multiple instantiations of a class template will trigger multiple matches for defined special members.
81// This should not cause problems.
82TemplateClass<int> InstantiationWithInt;
83TemplateClass<double> InstantiationWithDouble;
84

source code of clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions-relaxed.cpp