performance-inefficient-vector-operation false-negatives when looping on multiple vectors
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
When a loop performs inefficient operations on multiple vectors, performance-inefficient-vector-operation does not emit a warning.
```c++
#include
int main() {
std::vector bob;
std::vector 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
int main() {
// std::vector bob;
std::vector tom;
for (auto x = 0; x < 100; x++) {
// bob.emplace_back(x);
tom.push_back(x);
}
}
```
```
: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.
```
Contributor guide
Research direction
Reproduce the warning behavior with the two-vector C++ example and the single-vector variant from the issue. Start by locating the implementation and tests for performance-inefficient-vector-operation, then add coverage showing that both inefficient operations are diagnosed while preserving the existing single-vector warning behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100