Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
MitalAshok opened this issue Jun 14, 2024 · 0 comments · Fixed by #95667

Comments

@MitalAshok
Copy link
Contributor

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

@HerrCai0907 HerrCai0907 self-assigned this Jun 15, 2024
HerrCai0907 added a commit to HerrCai0907/llvm-project that referenced this issue Jun 15, 2024
…peration

Fixes: llvm#95596
Check will warn if the loop var type is not same as var init expr type
MitalAshok added a commit to MitalAshok/llvm-project that referenced this issue Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants