| Issue |
181427
|
| Summary |
performance-inefficient-vector-operation does not consider classes with inherited push_back/emplace_back methods
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
nick-potenski
|
When a custom vector class is defined and passed to performance-inefficient-vector-operation's VectorLikeClasses option, the class is not considered for the checker when the `push_back` or `emplace_back` function is inherited.
In the following, `foo`'s use in the loop will not trigger a warning while `bar`'s use will.
```c++
class MyVectorBase {
public:
void push_back(int) {}
};
class MyVector : public MyVectorBase {
public:
void reserve(int);
};
class MyVector2 {
public:
void push_back(int) {}
void reserve(int) {}
};
int main() {
MyVector foo;
for (int i = 0; i < 100; ++i) {
foo.push_back(i);
}
MyVector2 bar;
for (int i = 0; i < 100; ++i) {
bar.push_back(i);
}
return 0;
}
```
Command line options:
```
--checks=-*,performance-inefficient-vector-operation --config="{CheckOptions: {performance-inefficient-vector-operation.VectorLikeClasses: MyVector;MyVector2;MyVectorBase}}"
```
Result:
```
<source>:25:9: warning: 'push_back' is called inside a loop; consider pre-allocating the container capacity before the loop [performance-inefficient-vector-operation]
24 | for (int i = 0; i < 100; ++i) {
25 | bar.push_back(i);
| ^
1 warning generated.
```
See in compiler explorer [here](https://godbolt.org/z/sE11W6Gxe).
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs