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. |
4 | class DeclaresDestructor { |
5 | ~DeclaresDestructor(); |
6 | }; |
7 | |
8 | class DefinesDestructor { |
9 | ~DefinesDestructor(); |
10 | }; |
11 | DefinesDestructor::~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 | |
14 | class DefinesDefaultedDestructor { |
15 | ~DefinesDefaultedDestructor() = default; |
16 | }; |
17 | |
18 | class DefinesDefaultedDestructorOutside { |
19 | ~DefinesDefaultedDestructorOutside(); |
20 | }; |
21 | |
22 | DefinesDefaultedDestructorOutside::~DefinesDefaultedDestructorOutside() = default; |
23 | |
24 | class 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 | |
29 | class 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 | |
34 | class 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 | |
39 | class 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] |
43 | class DefinesNothing { |
44 | }; |
45 | |
46 | class DefinesEverything { |
47 | DefinesEverything(const DefinesEverything &); |
48 | DefinesEverything &operator=(const DefinesEverything &); |
49 | DefinesEverything(DefinesEverything &&); |
50 | DefinesEverything &operator=(DefinesEverything &&); |
51 | ~DefinesEverything(); |
52 | }; |
53 | |
54 | class 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 | |
62 | class 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 | |
70 | template <typename T> |
71 | struct 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. |
82 | TemplateClass<int> InstantiationWithInt; |
83 | TemplateClass<double> InstantiationWithDouble; |
84 | |