Issue 179458
Summary performance-inefficient-vector-operation false-negatives when looping on multiple vectors
Labels new issue
Assignees
Reporter nick-potenski
    When a loop performs inefficient operations on multiple vectors, performance-inefficient-vector-operation does not emit a warning.

```c++
#include <vector>

int main() {
    std::vector<int> bob;
    std::vector<float> tom;

    for (auto x = 0; x < 100; x++) {
 bob.emplace_back(x);
        tom.push_back(x);
    }
}
``` 

does not emit any warnings.  However, commenting out one or the other vectors from the same code does:

```c++
#include <vector>

int main() {
    // std::vector<int> bob;
    std::vector<float> tom;

    for (auto x = 0; x < 100; x++) {
        // bob.emplace_back(x);
        tom.push_back(x);
 }
}
``` 


```
<source>:9:9: warning: 'push_back' is called inside a loop; consider pre-allocating the container capacity before the loop [performance-inefficient-vector-operation]
    7 |     for (auto x = 0; x < 100; x++) {
    8 |         // bob.emplace_back(x);
    9 | tom.push_back(x);
      |         ^
1 warning generated.
``` 
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to