1
- // RUN: %check_clang_tidy -std=c++11-or-later %s bugprone-capturing-this-by-field %t
1
+ // RUN: %check_clang_tidy -std=c++11-or-later %s bugprone-capturing-this-by-field %t -- -config="{CheckOptions: {bugprone-capturing-this-by-field.FunctionWrapperTypes: '::std::function;::Fn'}}" --
2
2
3
3
namespace std {
4
4
@@ -14,18 +14,22 @@ class function<R(Args...)> {
14
14
15
15
} // namespace std
16
16
17
+ struct Fn {
18
+ template <class F > Fn (F &&);
19
+ };
20
+
17
21
struct Basic {
18
22
Basic () : Captured([this ]() { static_cast <void >(this ); }) {}
19
- // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: using lambda expressions to capture this and storing it in class member
23
+ // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: using lambda expressions to capture ' this' and storing it in class member
20
24
std::function<void ()> Captured;
21
- // CHECK-MESSAGES: :[[@LINE-1]]:25: note: 'std::function' that stores captured 'this;
25
+ // CHECK-MESSAGES: :[[@LINE-1]]:25: note: 'std::function<void (void)> ' that stores captured 'this'
22
26
};
23
27
24
28
struct AssignCapture {
25
29
AssignCapture () : Captured([Self = this ]() { static_cast <void >(Self); }) {}
26
- // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: using lambda expressions to capture this and storing it in class member
30
+ // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: using lambda expressions to capture ' this' and storing it in class member
27
31
std::function<void ()> Captured;
28
- // CHECK-MESSAGES: :[[@LINE-1]]:25: note: 'std::function' that stores captured 'this;
32
+ // CHECK-MESSAGES: :[[@LINE-1]]:25: note: 'std::function<void (void)> ' that stores captured 'this'
29
33
};
30
34
31
35
struct DeleteMoveAndCopy {
@@ -46,24 +50,24 @@ struct DeleteCopyImplicitDisabledMove {
46
50
47
51
struct DeleteCopyDefaultMove {
48
52
DeleteCopyDefaultMove () : Captured([this ]() { static_cast <void >(this ); }) {}
49
- // CHECK-MESSAGES: :[[@LINE-1]]:38: warning: using lambda expressions to capture this and storing it in class member
53
+ // CHECK-MESSAGES: :[[@LINE-1]]:38: warning: using lambda expressions to capture ' this' and storing it in class member
50
54
DeleteCopyDefaultMove (DeleteCopyDefaultMove const &) = delete ;
51
55
DeleteCopyDefaultMove (DeleteCopyDefaultMove &&) = default ;
52
56
DeleteCopyDefaultMove& operator =(DeleteCopyDefaultMove const &) = delete ;
53
57
DeleteCopyDefaultMove& operator =(DeleteCopyDefaultMove &&) = default ;
54
58
std::function<void ()> Captured;
55
- // CHECK-MESSAGES: :[[@LINE-1]]:25: note: 'std::function' that stores captured 'this;
59
+ // CHECK-MESSAGES: :[[@LINE-1]]:25: note: 'std::function<void (void)> ' that stores captured 'this'
56
60
};
57
61
58
62
struct DeleteMoveDefaultCopy {
59
63
DeleteMoveDefaultCopy () : Captured([this ]() { static_cast <void >(this ); }) {}
60
- // CHECK-MESSAGES: :[[@LINE-1]]:38: warning: using lambda expressions to capture this and storing it in class member
64
+ // CHECK-MESSAGES: :[[@LINE-1]]:38: warning: using lambda expressions to capture ' this' and storing it in class member
61
65
DeleteMoveDefaultCopy (DeleteMoveDefaultCopy const &) = default ;
62
66
DeleteMoveDefaultCopy (DeleteMoveDefaultCopy &&) = delete ;
63
67
DeleteMoveDefaultCopy& operator =(DeleteMoveDefaultCopy const &) = default ;
64
68
DeleteMoveDefaultCopy& operator =(DeleteMoveDefaultCopy &&) = delete ;
65
69
std::function<void ()> Captured;
66
- // CHECK-MESSAGES: :[[@LINE-1]]:25: note: 'std::function' that stores captured 'this;
70
+ // CHECK-MESSAGES: :[[@LINE-1]]:25: note: 'std::function<void (void)> ' that stores captured 'this'
67
71
};
68
72
69
73
struct DeleteCopyMoveBase {
@@ -90,44 +94,51 @@ struct UserDefinedCopyMove {
90
94
91
95
struct UserDefinedCopyMoveWithDefault1 {
92
96
UserDefinedCopyMoveWithDefault1 () : Captured([this ]() { static_cast <void >(this ); }) {}
93
- // CHECK-MESSAGES: :[[@LINE-1]]:48: warning: using lambda expressions to capture this and storing it in class member
97
+ // CHECK-MESSAGES: :[[@LINE-1]]:48: warning: using lambda expressions to capture ' this' and storing it in class member
94
98
UserDefinedCopyMoveWithDefault1 (UserDefinedCopyMoveWithDefault1 const &) = default ;
95
99
UserDefinedCopyMoveWithDefault1 (UserDefinedCopyMoveWithDefault1 &&);
96
100
UserDefinedCopyMoveWithDefault1& operator =(UserDefinedCopyMoveWithDefault1 const &);
97
101
UserDefinedCopyMoveWithDefault1& operator =(UserDefinedCopyMoveWithDefault1 &&);
98
102
std::function<void ()> Captured;
99
- // CHECK-MESSAGES: :[[@LINE-1]]:25: note: 'std::function' that stores captured 'this;
103
+ // CHECK-MESSAGES: :[[@LINE-1]]:25: note: 'std::function<void (void)> ' that stores captured 'this'
100
104
};
101
105
102
106
struct UserDefinedCopyMoveWithDefault2 {
103
107
UserDefinedCopyMoveWithDefault2 () : Captured([this ]() { static_cast <void >(this ); }) {}
104
- // CHECK-MESSAGES: :[[@LINE-1]]:48: warning: using lambda expressions to capture this and storing it in class member
108
+ // CHECK-MESSAGES: :[[@LINE-1]]:48: warning: using lambda expressions to capture ' this' and storing it in class member
105
109
UserDefinedCopyMoveWithDefault2 (UserDefinedCopyMoveWithDefault2 const &);
106
110
UserDefinedCopyMoveWithDefault2 (UserDefinedCopyMoveWithDefault2 &&) = default ;
107
111
UserDefinedCopyMoveWithDefault2& operator =(UserDefinedCopyMoveWithDefault2 const &);
108
112
UserDefinedCopyMoveWithDefault2& operator =(UserDefinedCopyMoveWithDefault2 &&);
109
113
std::function<void ()> Captured;
110
- // CHECK-MESSAGES: :[[@LINE-1]]:25: note: 'std::function' that stores captured 'this;
114
+ // CHECK-MESSAGES: :[[@LINE-1]]:25: note: 'std::function<void (void)> ' that stores captured 'this'
111
115
};
112
116
113
117
struct UserDefinedCopyMoveWithDefault3 {
114
118
UserDefinedCopyMoveWithDefault3 () : Captured([this ]() { static_cast <void >(this ); }) {}
115
- // CHECK-MESSAGES: :[[@LINE-1]]:48: warning: using lambda expressions to capture this and storing it in class member
119
+ // CHECK-MESSAGES: :[[@LINE-1]]:48: warning: using lambda expressions to capture ' this' and storing it in class member
116
120
UserDefinedCopyMoveWithDefault3 (UserDefinedCopyMoveWithDefault3 const &);
117
121
UserDefinedCopyMoveWithDefault3 (UserDefinedCopyMoveWithDefault3 &&);
118
122
UserDefinedCopyMoveWithDefault3& operator =(UserDefinedCopyMoveWithDefault3 const &) = default ;
119
123
UserDefinedCopyMoveWithDefault3& operator =(UserDefinedCopyMoveWithDefault3 &&);
120
124
std::function<void ()> Captured;
121
- // CHECK-MESSAGES: :[[@LINE-1]]:25: note: 'std::function' that stores captured 'this;
125
+ // CHECK-MESSAGES: :[[@LINE-1]]:25: note: 'std::function<void (void)> ' that stores captured 'this'
122
126
};
123
127
124
128
struct UserDefinedCopyMoveWithDefault4 {
125
129
UserDefinedCopyMoveWithDefault4 () : Captured([this ]() { static_cast <void >(this ); }) {}
126
- // CHECK-MESSAGES: :[[@LINE-1]]:48: warning: using lambda expressions to capture this and storing it in class member
130
+ // CHECK-MESSAGES: :[[@LINE-1]]:48: warning: using lambda expressions to capture ' this' and storing it in class member
127
131
UserDefinedCopyMoveWithDefault4 (UserDefinedCopyMoveWithDefault4 const &);
128
132
UserDefinedCopyMoveWithDefault4 (UserDefinedCopyMoveWithDefault4 &&);
129
133
UserDefinedCopyMoveWithDefault4& operator =(UserDefinedCopyMoveWithDefault4 const &);
130
134
UserDefinedCopyMoveWithDefault4& operator =(UserDefinedCopyMoveWithDefault4 &&) = default ;
131
135
std::function<void ()> Captured;
132
- // CHECK-MESSAGES: :[[@LINE-1]]:25: note: 'std::function' that stores captured 'this;
136
+ // CHECK-MESSAGES: :[[@LINE-1]]:25: note: 'std::function<void (void)>' that stores captured 'this'
137
+ };
138
+
139
+ struct CustomFunctionWrapper {
140
+ CustomFunctionWrapper () : Captured([this ]() { static_cast <void >(this ); }) {}
141
+ // CHECK-MESSAGES: :[[@LINE-1]]:38: warning: using lambda expressions to capture 'this' and storing it in class member
142
+ Fn Captured;
143
+ // CHECK-MESSAGES: :[[@LINE-1]]:6: note: 'Fn' that stores captured 'this'
133
144
};
0 commit comments