Skip to content

[clang-tidy] performance-inefficient-vector-operation doesn't warn if loop has unsigned index #95596

Closed
@MitalAshok

Description

@MitalAshok

https://godbolt.org/z/EWo1cTYGK

#include <vector>

void f(std::vector<int>& r) {
    std::vector<int> v;
    for (std::size_t i = 0; i < r.size(); ++i) {
        v.push_back(r[i]);
    }
}

void g(std::vector<int>& r) {
    std::vector<int> v;
    for (int i = 0; i < r.size(); ++i) {
        v.push_back(r[i]);
    }
}

The only difference is the loop variable i's type being std::size_t or int, but the check only warns to reserve for int i in g

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions