File tree Expand file tree Collapse file tree 3 files changed +31
-10
lines changed Expand file tree Collapse file tree 3 files changed +31
-10
lines changed Original file line number Diff line number Diff line change @@ -31,22 +31,20 @@ void ReturnConstRefFromParameterCheck::registerMatchers(MatchFinder *Finder) {
31
31
qualType (lValueReferenceType (pointee (
32
32
qualType (isConstQualified ()))))
33
33
.bind (" type" ))),
34
- hasDeclContext (functionDecl ().bind (" owner" )),
34
+ hasDeclContext (functionDecl (
35
+ equalsBoundNode (" func" ),
36
+ hasReturnTypeLoc (loc (qualType (
37
+ hasCanonicalType (equalsBoundNode (" type" ))))))),
35
38
unless (hasLifetimeBoundAttr ()))
36
39
.bind (" param" )))
37
40
.bind (" dref" ));
38
- const auto Func =
39
- functionDecl (equalsBoundNode (" owner" ),
40
- hasReturnTypeLoc (loc (
41
- qualType (hasCanonicalType (equalsBoundNode (" type" ))))))
42
- .bind (" func" );
43
41
44
42
Finder->addMatcher (
45
43
returnStmt (
44
+ hasAncestor (functionDecl ().bind (" func" )),
46
45
hasReturnValue (anyOf (
47
46
DRef, ignoringParens (conditionalOperator (eachOf (
48
- hasTrueExpression (DRef), hasFalseExpression (DRef)))))),
49
- hasAncestor (Func)),
47
+ hasTrueExpression (DRef), hasFalseExpression (DRef))))))),
50
48
this );
51
49
}
52
50
Original file line number Diff line number Diff line change @@ -183,8 +183,8 @@ Changes in existing checks
183
183
- Improved :doc: `bugprone-return-const-ref-from-parameter
184
184
<clang-tidy/checks/bugprone/return-const-ref-from-parameter>` check to
185
185
diagnose potential dangling references when returning a ``const & `` parameter
186
- by using the conditional operator ``cond ? var1 : var2 `` and no longer giving
187
- false positives for functions which contain lambda and ignore parameters
186
+ by using the conditional operator ``cond ? var1 : var2 `` and fixing false
187
+ positives for functions which contain lambda and ignore parameters
188
188
with ``[[clang::lifetimebound]] `` attribute.
189
189
190
190
- Improved :doc: `bugprone-sizeof-expression
Original file line number Diff line number Diff line change @@ -203,3 +203,26 @@ namespace use_lifetime_bound_attr {
203
203
int const &f (int const &a [[clang::lifetimebound]]) { return a; }
204
204
} // namespace use_lifetime_bound_attr
205
205
} // namespace gh117696
206
+
207
+
208
+ namespace lambda {
209
+ using T = const int &;
210
+ using K = const float &;
211
+ T inner_valid_lambda (T a) {
212
+ [&]() -> T { return a; };
213
+ return a;
214
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: returning a constant reference parameter
215
+ }
216
+ T inner_invalid_lambda (T a) {
217
+ [&](T a) -> T { return a; };
218
+ // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: returning a constant reference parameter
219
+ return a;
220
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: returning a constant reference parameter
221
+ }
222
+ T inner_invalid_lambda2 (T a) {
223
+ [&](K a) -> K { return a; };
224
+ // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: returning a constant reference parameter
225
+ return a;
226
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: returning a constant reference parameter
227
+ }
228
+ } // namespace lambda
You can’t perform that action at this time.
0 commit comments