================ @@ -387,3 +387,38 @@ void foo(const StructWithFieldContainer &Src) { B.push_back(Number); } } + +namespace gh95596 { + +void f(std::vector<int>& t) { + { + std::vector<int> gh95596_0; + // CHECK-FIXES: gh95596_0.reserve(10); + for (unsigned i = 0; i < 10; ++i) + gh95596_0.push_back(i); + // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called inside a loop; consider pre-allocating the container capacity before the loop + } + { + std::vector<int> gh95596_1; + // CHECK-FIXES: gh95596_1.reserve(10); + for (int i = 0U; i < 10; ++i) + gh95596_1.push_back(i); + // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called inside a loop; consider pre-allocating the container capacity before the loop + } + { + std::vector<int> gh95596_2; + // CHECK-FIXES: gh95596_2.reserve(10); + for (unsigned i = 0U; i < 10; ++i) + gh95596_2.push_back(i); + // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called inside a loop; consider pre-allocating the container capacity before the loop + } + { + std::vector<int> gh95596_3; + // CHECK-FIXES: gh95596_3.reserve(10U); + for (int i = 0; i < 10U; ++i) + gh95596_3.push_back(i); + // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called inside a loop; consider pre-allocating the container capacity before the loop + } +} + +} // namespace gh95596 ---------------- 5chmidti wrote:
missing newline https://github.com/llvm/llvm-project/pull/95667 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits