You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/owning-memory.cpp
+106Lines changed: 106 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -395,3 +395,109 @@ namespace PR63994 {
395
395
// CHECK-NOTES: [[@LINE-1]]:5: warning: returning a newly created resource of type 'A *' or 'gsl::owner<>' from a function whose return type is not 'gsl::owner<>'
396
396
}
397
397
}
398
+
399
+
namespacePR59389 {
400
+
structS {
401
+
S();
402
+
S(int);
403
+
404
+
int value = 1;
405
+
};
406
+
407
+
voidtestLambdaInFunctionNegative() {
408
+
constauto MakeS = []() -> ::gsl::owner<S*> {
409
+
return ::gsl::owner<S*>{new S{}};
410
+
};
411
+
}
412
+
413
+
voidtestLambdaInFunctionPositive() {
414
+
constauto MakeS = []() -> S* {
415
+
return ::gsl::owner<S*>{new S{}};
416
+
// CHECK-NOTES: [[@LINE-1]]:7: warning: returning a newly created resource of type 'S *' or 'gsl::owner<>' from a lambda whose return type is not 'gsl::owner<>'
417
+
};
418
+
}
419
+
420
+
voidtestFunctionInFunctionNegative() {
421
+
structC {
422
+
::gsl::owner<S*> test() {
423
+
return ::gsl::owner<S*>{new S{}};
424
+
}
425
+
};
426
+
}
427
+
428
+
voidtestFunctionInFunctionPositive() {
429
+
structC {
430
+
S* test() {
431
+
return ::gsl::owner<S*>{new S{}};
432
+
// CHECK-NOTES: [[@LINE-1]]:9: warning: returning a newly created resource of type 'S *' or 'gsl::owner<>' from a function whose return type is not 'gsl::owner<>'
433
+
}
434
+
};
435
+
}
436
+
437
+
::gsl::owner<S*> testReverseLambdaNegative() {
438
+
constauto MakeI = [] -> int { return5; };
439
+
return ::gsl::owner<S*>{newS(MakeI())};
440
+
}
441
+
442
+
S* testReverseLambdaPositive() {
443
+
constauto MakeI = [] -> int { return5; };
444
+
return ::gsl::owner<S*>{newS(MakeI())};
445
+
// CHECK-NOTES: [[@LINE-1]]:5: warning: returning a newly created resource of type 'S *' or 'gsl::owner<>' from a function whose return type is not 'gsl::owner<>'
446
+
}
447
+
448
+
::gsl::owner<S*> testReverseFunctionNegative() {
449
+
structC {
450
+
inttest() { return5; }
451
+
};
452
+
return ::gsl::owner<S*>{newS(C().test())};
453
+
}
454
+
455
+
S* testReverseFunctionPositive() {
456
+
structC {
457
+
inttest() { return5; }
458
+
};
459
+
return ::gsl::owner<S*>{newS(C().test())};
460
+
// CHECK-NOTES: [[@LINE-1]]:5: warning: returning a newly created resource of type 'S *' or 'gsl::owner<>' from a function whose return type is not 'gsl::owner<>'
461
+
}
462
+
463
+
voidtestLambdaInLambdaNegative() {
464
+
constauto MakeS = []() -> ::gsl::owner<S*> {
465
+
constauto MakeI = []() -> int { return5; };
466
+
return ::gsl::owner<S*>{newS(MakeI())};
467
+
};
468
+
}
469
+
470
+
voidtestLambdaInLambdaPositive() {
471
+
constauto MakeS = []() -> S* {
472
+
constauto MakeI = []() -> int { return5; };
473
+
return ::gsl::owner<S*>{newS(MakeI())};
474
+
// CHECK-NOTES: [[@LINE-1]]:7: warning: returning a newly created resource of type 'S *' or 'gsl::owner<>' from a lambda whose return type is not 'gsl::owner<>'
475
+
};
476
+
}
477
+
478
+
voidtestLambdaInLambdaWithDoubleReturns() {
479
+
constauto MakeS = []() -> S* {
480
+
constauto MakeS2 = []() -> S* {
481
+
return ::gsl::owner<S*>{newS(1)};
482
+
// CHECK-NOTES: [[@LINE-1]]:9: warning: returning a newly created resource of type 'S *' or 'gsl::owner<>' from a lambda whose return type is not 'gsl::owner<>' [cppcoreguidelines-owning-memory]
483
+
};
484
+
return ::gsl::owner<S*>{newS(2)};
485
+
// CHECK-NOTES: [[@LINE-1]]:7: warning: returning a newly created resource of type 'S *' or 'gsl::owner<>' from a lambda whose return type is not 'gsl::owner<>'
486
+
};
487
+
}
488
+
489
+
voidtestReverseLambdaInLambdaNegative() {
490
+
constauto MakeI = []() -> int {
491
+
constauto MakeS = []() -> ::gsl::owner<S*> { returnnewS(); };
492
+
return5;
493
+
};
494
+
}
495
+
496
+
voidtestReverseLambdaInLambdaPositive() {
497
+
constauto MakeI = []() -> int {
498
+
constauto MakeS = []() -> S* { returnnewS(); };
499
+
// CHECK-NOTES: [[@LINE-1]]:39: warning: returning a newly created resource of type 'S *' or 'gsl::owner<>' from a lambda whose return type is not 'gsl::owner<>'
0 commit comments