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'}}" --
22
33namespace std {
44
@@ -14,18 +14,22 @@ class function<R(Args...)> {
1414
1515} // namespace std
1616
17+ struct Fn {
18+ template <class F > Fn (F &&);
19+ };
20+
1721struct Basic {
1822 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
2024 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'
2226};
2327
2428struct AssignCapture {
2529 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
2731 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'
2933};
3034
3135struct DeleteMoveAndCopy {
@@ -46,24 +50,24 @@ struct DeleteCopyImplicitDisabledMove {
4650
4751struct DeleteCopyDefaultMove {
4852 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
5054 DeleteCopyDefaultMove (DeleteCopyDefaultMove const &) = delete ;
5155 DeleteCopyDefaultMove (DeleteCopyDefaultMove &&) = default ;
5256 DeleteCopyDefaultMove& operator =(DeleteCopyDefaultMove const &) = delete ;
5357 DeleteCopyDefaultMove& operator =(DeleteCopyDefaultMove &&) = default ;
5458 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'
5660};
5761
5862struct DeleteMoveDefaultCopy {
5963 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
6165 DeleteMoveDefaultCopy (DeleteMoveDefaultCopy const &) = default ;
6266 DeleteMoveDefaultCopy (DeleteMoveDefaultCopy &&) = delete ;
6367 DeleteMoveDefaultCopy& operator =(DeleteMoveDefaultCopy const &) = default ;
6468 DeleteMoveDefaultCopy& operator =(DeleteMoveDefaultCopy &&) = delete ;
6569 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'
6771};
6872
6973struct DeleteCopyMoveBase {
@@ -90,44 +94,51 @@ struct UserDefinedCopyMove {
9094
9195struct UserDefinedCopyMoveWithDefault1 {
9296 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
9498 UserDefinedCopyMoveWithDefault1 (UserDefinedCopyMoveWithDefault1 const &) = default ;
9599 UserDefinedCopyMoveWithDefault1 (UserDefinedCopyMoveWithDefault1 &&);
96100 UserDefinedCopyMoveWithDefault1& operator =(UserDefinedCopyMoveWithDefault1 const &);
97101 UserDefinedCopyMoveWithDefault1& operator =(UserDefinedCopyMoveWithDefault1 &&);
98102 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'
100104};
101105
102106struct UserDefinedCopyMoveWithDefault2 {
103107 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
105109 UserDefinedCopyMoveWithDefault2 (UserDefinedCopyMoveWithDefault2 const &);
106110 UserDefinedCopyMoveWithDefault2 (UserDefinedCopyMoveWithDefault2 &&) = default ;
107111 UserDefinedCopyMoveWithDefault2& operator =(UserDefinedCopyMoveWithDefault2 const &);
108112 UserDefinedCopyMoveWithDefault2& operator =(UserDefinedCopyMoveWithDefault2 &&);
109113 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'
111115};
112116
113117struct UserDefinedCopyMoveWithDefault3 {
114118 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
116120 UserDefinedCopyMoveWithDefault3 (UserDefinedCopyMoveWithDefault3 const &);
117121 UserDefinedCopyMoveWithDefault3 (UserDefinedCopyMoveWithDefault3 &&);
118122 UserDefinedCopyMoveWithDefault3& operator =(UserDefinedCopyMoveWithDefault3 const &) = default ;
119123 UserDefinedCopyMoveWithDefault3& operator =(UserDefinedCopyMoveWithDefault3 &&);
120124 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'
122126};
123127
124128struct UserDefinedCopyMoveWithDefault4 {
125129 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
127131 UserDefinedCopyMoveWithDefault4 (UserDefinedCopyMoveWithDefault4 const &);
128132 UserDefinedCopyMoveWithDefault4 (UserDefinedCopyMoveWithDefault4 &&);
129133 UserDefinedCopyMoveWithDefault4& operator =(UserDefinedCopyMoveWithDefault4 const &);
130134 UserDefinedCopyMoveWithDefault4& operator =(UserDefinedCopyMoveWithDefault4 &&) = default ;
131135 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'
133144};
0 commit comments