File tree Expand file tree Collapse file tree 3 files changed +43
-3
lines changed Expand file tree Collapse file tree 3 files changed +43
-3
lines changed Original file line number Diff line number Diff line change @@ -105,9 +105,9 @@ void InefficientVectorOperationCheck::addMatcher(
105
105
onImplicitObjectArgument (declRefExpr (to (TargetVarDecl))))
106
106
.bind (AppendCallName);
107
107
const auto AppendCall = expr (ignoringImplicit (AppendCallExpr));
108
- const auto LoopVarInit =
109
- declStmt ( hasSingleDecl ( varDecl (hasInitializer (integerLiteral (equals (0 ))))
110
- .bind (LoopInitVarName)));
108
+ const auto LoopVarInit = declStmt ( hasSingleDecl (
109
+ varDecl (hasInitializer (ignoringParenImpCasts ( integerLiteral (equals (0 ) ))))
110
+ .bind (LoopInitVarName)));
111
111
const auto RefersToLoopVar = ignoringParenImpCasts (
112
112
declRefExpr (to (varDecl (equalsBoundNode (LoopInitVarName)))));
113
113
Original file line number Diff line number Diff line change @@ -387,6 +387,11 @@ Changes in existing checks
387
387
- Improved :doc: `modernize-use-using <clang-tidy/checks/modernize/use-using >`
388
388
check by adding support for detection of typedefs declared on function level.
389
389
390
+ - Improved :doc: `performance-inefficient-vector-operation
391
+ <clang-tidy/checks/performance/inefficient-vector-operation>` fixing false
392
+ negatives caused by different variable definition type and variable initial
393
+ value type in loop initialization expression.
394
+
390
395
- Improved :doc: `performance-move-const-arg
391
396
<clang-tidy/checks/performance/move-const-arg>` check by ignoring
392
397
``std::move() `` calls when their target is used as an rvalue.
Original file line number Diff line number Diff line change @@ -387,3 +387,38 @@ void foo(const StructWithFieldContainer &Src) {
387
387
B.push_back (Number);
388
388
}
389
389
}
390
+
391
+ namespace gh95596 {
392
+
393
+ void f (std::vector<int >& t) {
394
+ {
395
+ std::vector<int > gh95596_0;
396
+ // CHECK-FIXES: gh95596_0.reserve(10);
397
+ for (unsigned i = 0 ; i < 10 ; ++i)
398
+ gh95596_0.push_back (i);
399
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called inside a loop; consider pre-allocating the container capacity before the loop
400
+ }
401
+ {
402
+ std::vector<int > gh95596_1;
403
+ // CHECK-FIXES: gh95596_1.reserve(10);
404
+ for (int i = 0U ; i < 10 ; ++i)
405
+ gh95596_1.push_back (i);
406
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called inside a loop; consider pre-allocating the container capacity before the loop
407
+ }
408
+ {
409
+ std::vector<int > gh95596_2;
410
+ // CHECK-FIXES: gh95596_2.reserve(10);
411
+ for (unsigned i = 0U ; i < 10 ; ++i)
412
+ gh95596_2.push_back (i);
413
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called inside a loop; consider pre-allocating the container capacity before the loop
414
+ }
415
+ {
416
+ std::vector<int > gh95596_3;
417
+ // CHECK-FIXES: gh95596_3.reserve(10U);
418
+ for (int i = 0 ; i < 10U ; ++i)
419
+ gh95596_3.push_back (i);
420
+ // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called inside a loop; consider pre-allocating the container capacity before the loop
421
+ }
422
+ }
423
+
424
+ } // namespace gh95596
You can’t perform that action at this time.
0 commit comments