1 | // RUN: %check_clang_tidy %s cppcoreguidelines-special-member-functions %t |
2 | |
3 | class DefinesDestructor { |
4 | ~DefinesDestructor(); |
5 | }; |
6 | // CHECK-MESSAGES: [[@LINE-3]]:7: warning: class 'DefinesDestructor' defines a destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions] |
7 | |
8 | class DefinesDefaultedDestructor { |
9 | ~DefinesDefaultedDestructor() = default; |
10 | }; |
11 | // CHECK-MESSAGES: [[@LINE-3]]:7: warning: class 'DefinesDefaultedDestructor' defines a default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions] |
12 | |
13 | class DefinesCopyConstructor { |
14 | DefinesCopyConstructor(const DefinesCopyConstructor &); |
15 | }; |
16 | // CHECK-MESSAGES: [[@LINE-3]]:7: warning: class 'DefinesCopyConstructor' defines a copy constructor but does not define a destructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions] |
17 | |
18 | class DefinesCopyAssignment { |
19 | DefinesCopyAssignment &operator=(const DefinesCopyAssignment &); |
20 | }; |
21 | // CHECK-MESSAGES: [[@LINE-3]]:7: warning: class 'DefinesCopyAssignment' defines a copy assignment operator but does not define a destructor, a copy constructor, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions] |
22 | |
23 | class DefinesMoveConstructor { |
24 | DefinesMoveConstructor(DefinesMoveConstructor &&); |
25 | }; |
26 | // 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] |
27 | |
28 | class DefinesMoveAssignment { |
29 | DefinesMoveAssignment &operator=(DefinesMoveAssignment &&); |
30 | }; |
31 | // 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] |
32 | class DefinesNothing { |
33 | }; |
34 | |
35 | class DefinesEverything { |
36 | DefinesEverything(const DefinesEverything &); |
37 | DefinesEverything &operator=(const DefinesEverything &); |
38 | DefinesEverything(DefinesEverything &&); |
39 | DefinesEverything &operator=(DefinesEverything &&); |
40 | ~DefinesEverything(); |
41 | }; |
42 | |
43 | class DeletesEverything { |
44 | DeletesEverything(const DeletesEverything &) = delete; |
45 | DeletesEverything &operator=(const DeletesEverything &) = delete; |
46 | DeletesEverything(DeletesEverything &&) = delete; |
47 | DeletesEverything &operator=(DeletesEverything &&) = delete; |
48 | ~DeletesEverything() = delete; |
49 | }; |
50 | |
51 | class DeletesCopyDefaultsMove { |
52 | DeletesCopyDefaultsMove(const DeletesCopyDefaultsMove &) = delete; |
53 | DeletesCopyDefaultsMove &operator=(const DeletesCopyDefaultsMove &) = delete; |
54 | DeletesCopyDefaultsMove(DeletesCopyDefaultsMove &&) = default; |
55 | DeletesCopyDefaultsMove &operator=(DeletesCopyDefaultsMove &&) = default; |
56 | ~DeletesCopyDefaultsMove() = default; |
57 | }; |
58 | |
59 | template <typename T> |
60 | struct TemplateClass { |
61 | TemplateClass() = default; |
62 | TemplateClass(const TemplateClass &); |
63 | TemplateClass &operator=(const TemplateClass &); |
64 | TemplateClass(TemplateClass &&); |
65 | TemplateClass &operator=(TemplateClass &&); |
66 | ~TemplateClass(); |
67 | }; |
68 | |
69 | // Multiple instantiations of a class template will trigger multiple matches for defined special members. |
70 | // This should not cause problems. |
71 | TemplateClass<int> InstantiationWithInt; |
72 | TemplateClass<double> InstantiationWithDouble; |
73 | |